Best JavaScript code snippet using best
runServer.js
Source:runServer.js
1/**2 * Copyright (c) 2015-present, Facebook, Inc.3 * All rights reserved.4 *5 * This source code is licensed under the BSD-style license found in the6 * LICENSE file in the root directory of this source tree. An additional grant7 * of patent rights can be found in the PATENTS file in the same directory.8 */9'use strict';10const InspectorProxy = require('./util/inspectorProxy.js');11const ReactPackager = require('../../packager/react-packager');12const attachHMRServer = require('./util/attachHMRServer');13const connect = require('connect');14const copyToClipBoardMiddleware = require('./middleware/copyToClipBoardMiddleware');15const cpuProfilerMiddleware = require('./middleware/cpuProfilerMiddleware');16const defaultAssetExts = require('../../packager/defaults').assetExts;17const defaultPlatforms = require('../../packager/defaults').platforms;18const defaultProvidesModuleNodeModules = require('../../packager/defaults').providesModuleNodeModules;19const getDevToolsMiddleware = require('./middleware/getDevToolsMiddleware');20const http = require('http');21const indexPageMiddleware = require('./middleware/indexPage');22const loadRawBodyMiddleware = require('./middleware/loadRawBodyMiddleware');23const messageSocket = require('./util/messageSocket.js');24const openStackFrameInEditorMiddleware = require('./middleware/openStackFrameInEditorMiddleware');25const path = require('path');26const statusPageMiddleware = require('./middleware/statusPageMiddleware.js');27const systraceProfileMiddleware = require('./middleware/systraceProfileMiddleware.js');28const unless = require('./middleware/unless');29const webSocketProxy = require('./util/webSocketProxy.js');30function runServer(args, config, startedCallback, readyCallback) {31 var wsProxy = null;32 var ms = null;33 const packagerServer = getPackagerServer(args, config);34 startedCallback(packagerServer._reporter);35 const inspectorProxy = new InspectorProxy();36 const app = connect()37 .use(loadRawBodyMiddleware)38 .use(connect.compress())39 .use(getDevToolsMiddleware(args, () => wsProxy && wsProxy.isChromeConnected()))40 .use(getDevToolsMiddleware(args, () => ms && ms.isChromeConnected()))41 .use(openStackFrameInEditorMiddleware(args))42 .use(copyToClipBoardMiddleware)43 .use(statusPageMiddleware)44 .use(systraceProfileMiddleware)45 .use(cpuProfilerMiddleware)46 .use(indexPageMiddleware)47 .use(unless('/inspector', inspectorProxy.processRequest.bind(inspectorProxy)))48 .use(packagerServer.processRequest.bind(packagerServer));49 args.projectRoots.forEach(root => app.use(connect.static(root)));50 app.use(connect.logger())51 .use(connect.errorHandler());52 const serverInstance = http.createServer(app).listen(53 args.port,54 args.host,55 function() {56 attachHMRServer({57 httpServer: serverInstance,58 path: '/hot',59 packagerServer,60 });61 wsProxy = webSocketProxy.attachToServer(serverInstance, '/debugger-proxy');62 ms = messageSocket.attachToServer(serverInstance, '/message');63 inspectorProxy.attachToServer(serverInstance, '/inspector');64 readyCallback(packagerServer._reporter);65 }66 );67 // Disable any kind of automatic timeout behavior for incoming68 // requests in case it takes the packager more than the default69 // timeout of 120 seconds to respond to a request.70 serverInstance.timeout = 0;71}72function getPackagerServer(args, config) {73 const transformModulePath =74 args.transformer ? path.resolve(args.transformer) :75 typeof config.getTransformModulePath === 'function' ? config.getTransformModulePath() :76 undefined;77 const providesModuleNodeModules =78 args.providesModuleNodeModules || defaultProvidesModuleNodeModules;79 let LogReporter;80 if (args.customLogReporterPath) {81 try {82 // First we let require resolve it, so we can require packages in node_modules83 // as expected. eg: require('my-package/reporter');84 LogReporter = require(args.customLogReporterPath);85 } catch(e) {86 // If that doesn't work, then we next try relative to the cwd, eg:87 // require('./reporter');88 LogReporter = require(path.resolve(args.customLogReporterPath));89 }90 } else {91 LogReporter = require('../../packager/src/lib/TerminalReporter');92 }93 return ReactPackager.createServer({94 assetExts: defaultAssetExts.concat(args.assetExts),95 blacklistRE: config.getBlacklistRE(),96 cacheVersion: '3',97 extraNodeModules: config.extraNodeModules,98 getTransformOptions: config.getTransformOptions,99 hasteImpl: config.hasteImpl,100 platforms: defaultPlatforms.concat(args.platforms),101 projectRoots: args.projectRoots,102 providesModuleNodeModules: providesModuleNodeModules,103 reporter: new LogReporter(),104 resetCache: args.resetCache,105 transformModulePath: transformModulePath,106 verbose: args.verbose,107 watch: !args.nonPersistent,108 });109}...
default.js
Source:default.js
1module.exports = app => {2 const { router, controller } = app;3 // é
置路ç±ä¸é´ä»¶4 const initMiddleware = app.middleware.init({}, app);5 const userauthMiddleware = app.middleware.userauth({}, app);6 const xmlparseMiddleware = app.middleware.xmlparse();7 router.get('/', initMiddleware, controller.default.index.index);8 router.get('/plist', initMiddleware, controller.default.product.list);9 router.get('/pinfo', initMiddleware, controller.default.product.info);10 router.get('/getImagelist', initMiddleware, controller.default.product.getImagelist);11 // è´ç©è½¦12 router.get('/addCart', controller.default.cart.addCart);13 router.get('/cart', initMiddleware, controller.default.cart.cartList);14 router.get('/addCartSuccess', initMiddleware, controller.default.cart.addCartSuccess);15 router.get('/incCart', initMiddleware, controller.default.cart.incCart);16 router.get('/decCart', initMiddleware, controller.default.cart.decCart);17 router.get('/changeOneCart', initMiddleware, controller.default.cart.changeOneCart);18 router.get('/changeAllCart', initMiddleware, controller.default.cart.changeAllCart);19 router.get('/removeCart', initMiddleware, controller.default.cart.removeCart);20 // ç¨æ·æ³¨åç»å½21 router.get('/login', initMiddleware, controller.default.pass.login);22 router.post('/pass/doLogin', initMiddleware, controller.default.pass.doLogin);23 router.get('/register/registerStep1', initMiddleware, controller.default.pass.registerStep1);24 router.get('/register/registerStep2', initMiddleware, controller.default.pass.registerStep2);25 router.get('/register/registerStep3', initMiddleware, controller.default.pass.registerStep3);26 router.get('/pass/sendCode', initMiddleware, controller.default.pass.sendCode);27 router.get('/pass/validatePhoneCode', initMiddleware, controller.default.pass.validatePhoneCode);28 router.post('/pass/doRegister', initMiddleware, controller.default.pass.doRegister);29 router.get('/pass/loginOut', initMiddleware, controller.default.pass.loginOut);30 // éªè¯ç 31 router.get('/verify', initMiddleware, controller.default.base.verify);32 // å»ç»ç®33 router.get('/buy/checkout', initMiddleware, userauthMiddleware, controller.default.buy.checkout);34 35 //确认订åå»æ¯ä»36 router.get('/buy/confirm', initMiddleware, userauthMiddleware, controller.default.buy.confirm);37 38 //æ交订å39 router.post('/buy/doOrder', initMiddleware, userauthMiddleware, controller.default.buy.doOrder);40 //æ£æµè®¢åæ¯å¦æ¯ä»41 router.get('/buy/getOrderPayStatus', initMiddleware, userauthMiddleware, controller.default.buy.getOrderPayStatus);42 //æ¯ä»43 router.get('/alipay/pay', initMiddleware, controller.default.alipay.pay);44//æ¯ä»æååè°45 router.get('/alipay/alipayReturn', initMiddleware, controller.default.alipay.alipayReturn);46//æ¯ä»æåå¼æ¥éç¥ æ³¨æå
³écsrféªè¯47 router.post('/alipay/alipayNotify', initMiddleware,xmlparseMiddleware, controller.default.alipay.alipayNotify);48// 微信æ¯ä»49router.get('/weixinpay/pay', initMiddleware, controller.default.weixinpay.pay);50//å¼æ¥éç¥ æ³¨æå
³écsrféªè¯51router.post('/weixinpay/weixinpayNotify', initMiddleware,xmlparseMiddleware, controller.default.weixinpay.weixinpayNotify);52 // address æ¶è´§å°åï¼apiæ¥å£ï¼53 router.post('/user/addAddress', initMiddleware, userauthMiddleware, controller.default.address.addAddress);54 router.get('/user/getAddressList', initMiddleware, userauthMiddleware, controller.default.address.getAddressList);55 router.get('/user/getOneAddressList', initMiddleware, userauthMiddleware, controller.default.address.getOneAddressList);56 router.get('/user/changeDefaultAddress', initMiddleware, userauthMiddleware, controller.default.address.changeDefaultAddress);57 router.post('/user/editAddress', initMiddleware, userauthMiddleware, controller.default.address.editAddress);58 59 // ç¨æ·ä¸å¿60 router.get('/user/welcome', initMiddleware, userauthMiddleware, controller.default.user.welcome);61 router.get('/user/order', initMiddleware, userauthMiddleware, controller.default.user.order);62 63 router.get('/user/orderinfo', initMiddleware, userauthMiddleware, controller.default.user.orderinfo);64 65 ...
webpack-hot-middleware_vx.x.x.js
Source:webpack-hot-middleware_vx.x.x.js
1// flow-typed signature: 120f34f625f7d493bfaf70e8761ae58b2// flow-typed version: <<STUB>>/webpack-hot-middleware_v^2.15.0/flow_v0.38.03/**4 * This is an autogenerated libdef stub for:5 *6 * 'webpack-hot-middleware'7 *8 * Fill this stub out by replacing all the `any` types.9 *10 * Once filled out, we encourage you to share your work with the 11 * community by sending a pull request to: 12 * https://github.com/flowtype/flow-typed13 */14declare module 'webpack-hot-middleware' {15 declare module.exports: any;16}17/**18 * We include stubs for each file inside this npm package in case you need to19 * require those files directly. Feel free to delete any files that aren't20 * needed.21 */22declare module 'webpack-hot-middleware/client-overlay' {23 declare module.exports: any;24}25declare module 'webpack-hot-middleware/client' {26 declare module.exports: any;27}28declare module 'webpack-hot-middleware/example/client' {29 declare module.exports: any;30}31declare module 'webpack-hot-middleware/example/extra' {32 declare module.exports: any;33}34declare module 'webpack-hot-middleware/example/server' {35 declare module.exports: any;36}37declare module 'webpack-hot-middleware/example/webpack.config' {38 declare module.exports: any;39}40declare module 'webpack-hot-middleware/example/webpack.config.multientry' {41 declare module.exports: any;42}43declare module 'webpack-hot-middleware/helpers' {44 declare module.exports: any;45}46declare module 'webpack-hot-middleware/middleware' {47 declare module.exports: any;48}49declare module 'webpack-hot-middleware/process-update' {50 declare module.exports: any;51}52declare module 'webpack-hot-middleware/test/client-test' {53 declare module.exports: any;54}55declare module 'webpack-hot-middleware/test/helpers-test' {56 declare module.exports: any;57}58declare module 'webpack-hot-middleware/test/middleware-test' {59 declare module.exports: any;60}61// Filename aliases62declare module 'webpack-hot-middleware/client-overlay.js' {63 declare module.exports: $Exports<'webpack-hot-middleware/client-overlay'>;64}65declare module 'webpack-hot-middleware/client.js' {66 declare module.exports: $Exports<'webpack-hot-middleware/client'>;67}68declare module 'webpack-hot-middleware/example/client.js' {69 declare module.exports: $Exports<'webpack-hot-middleware/example/client'>;70}71declare module 'webpack-hot-middleware/example/extra.js' {72 declare module.exports: $Exports<'webpack-hot-middleware/example/extra'>;73}74declare module 'webpack-hot-middleware/example/server.js' {75 declare module.exports: $Exports<'webpack-hot-middleware/example/server'>;76}77declare module 'webpack-hot-middleware/example/webpack.config.js' {78 declare module.exports: $Exports<'webpack-hot-middleware/example/webpack.config'>;79}80declare module 'webpack-hot-middleware/example/webpack.config.multientry.js' {81 declare module.exports: $Exports<'webpack-hot-middleware/example/webpack.config.multientry'>;82}83declare module 'webpack-hot-middleware/helpers.js' {84 declare module.exports: $Exports<'webpack-hot-middleware/helpers'>;85}86declare module 'webpack-hot-middleware/middleware.js' {87 declare module.exports: $Exports<'webpack-hot-middleware/middleware'>;88}89declare module 'webpack-hot-middleware/process-update.js' {90 declare module.exports: $Exports<'webpack-hot-middleware/process-update'>;91}92declare module 'webpack-hot-middleware/test/client-test.js' {93 declare module.exports: $Exports<'webpack-hot-middleware/test/client-test'>;94}95declare module 'webpack-hot-middleware/test/helpers-test.js' {96 declare module.exports: $Exports<'webpack-hot-middleware/test/helpers-test'>;97}98declare module 'webpack-hot-middleware/test/middleware-test.js' {99 declare module.exports: $Exports<'webpack-hot-middleware/test/middleware-test'>;...
telegram-login.spec.js
Source:telegram-login.spec.js
...50 });51 it('should call next() once', function * (){52 const middleware = myLogin.defaultMiddleware();53 const nextSpy = chai.spy();54 const result = middleware({query: valid_payload}, {locals: {}}, nextSpy)55 expect(nextSpy).to.have.been.called.once;56 });57 it('should set res.locals.telegram_user to data', function * (){58 const middleware = myLogin.defaultMiddleware();59 const nextSpy = chai.spy();60 const res = {locals: {}};61 const result = middleware({query: valid_payload}, res, nextSpy)62 expect(res.locals.telegram_user).to.eql(valid_data)63 });64})65describe('customMiddleware', function () {66 it('should return a function()', function * () {67 const middleware = myLogin.customMiddleware(() => null, () => null);68 expect(middleware).to.be.an('function');69 });70 it('should accept three arguments', function * () {71 const middleware = myLogin.customMiddleware(() => null, () => null);72 expect(middleware.length).to.equal(3);73 });74 it('should call success() once', function * (){75 const successSpy = chai.spy()76 const nextSpy = chai.spy();77 const middleware = myLogin.customMiddleware(successSpy, () => null);78 const res = {locals: {}};79 const result = middleware({query: valid_payload}, res, nextSpy)80 expect(successSpy).to.have.been.called.once;81 });82 it('should call fail() once', function * (){83 const failSpy = chai.spy()84 const nextSpy = chai.spy();85 const middleware = myLogin.customMiddleware(() => null,failSpy);86 const res = {locals: {}};87 const result = middleware({query: invalid_payload}, res, nextSpy)88 expect(failSpy).to.have.been.called.once;89 });...
kernel.js
Source:kernel.js
...27| auth: 'Adonis/Middleware/Auth'28| }29|30| // use31| Route.get().middleware('auth')32|33*/34const namedMiddleware = {35 auth: 'Adonis/Middleware/Auth',36 guest: 'Adonis/Middleware/AllowGuestOnly'37}38/*39|--------------------------------------------------------------------------40| Server Middleware41|--------------------------------------------------------------------------42|43| Server level middleware are executed even when route for a given URL is44| not registered. Features like `static assets` and `cors` needs better45| control over request lifecycle....
CreateStore.js
Source:CreateStore.js
1import { createStore, applyMiddleware, compose } from 'redux'2import Rehydration from '../Services/Rehydration'3import ReduxPersist from '../Config/ReduxPersist'4import Config from '../Config/DebugConfig'5import createSagaMiddleware from 'redux-saga'6import ScreenTracking from './ScreenTrackingMiddleware'7// creates the store8export default (rootReducer, rootSaga) => {9 /* ------------- Redux Configuration ------------- */10 const middleware = []11 const enhancers = []12 /* ------------- Analytics Middleware ------------- */13 middleware.push(ScreenTracking)14 /* ------------- Saga Middleware ------------- */15 const sagaMonitor = Config.useReactotron ? console.tron.createSagaMonitor() : null16 const sagaMiddleware = createSagaMiddleware({ sagaMonitor })17 middleware.push(sagaMiddleware)18 /* ------------- Assemble Middleware ------------- */19 enhancers.push(applyMiddleware(...middleware))20 // if Reactotron is enabled (default for __DEV__), we'll create the store through Reactotron21 const createAppropriateStore = Config.useReactotron ? console.tron.createStore : createStore22 const store = createAppropriateStore(rootReducer, compose(...enhancers))23 // configure persistStore and check reducer version number24 if (ReduxPersist.active) {25 Rehydration.updateReducers(store)26 }27 // kick off root saga28 let sagasManager = sagaMiddleware.run(rootSaga)29 return {30 store,31 sagasManager,32 sagaMiddleware33 }...
store.js
Source:store.js
1import { applyMiddleware, createStore } from 'redux';2import { createLogger } from 'redux-logger'3import { composeWithDevTools } from 'redux-devtools-extension/developmentOnly';4import { promiseMiddleware, localStorageMiddleware } from './middleware';5import reducer from './reducer';6import { routerMiddleware } from 'react-router-redux'7import createHistory from 'history/createBrowserHistory';8export const history = createHistory();9// Build the middleware for intercepting and dispatching navigation actions10const myRouterMiddleware = routerMiddleware(history);11const getMiddleware = () => {12 if (process.env.NODE_ENV === 'production') {13 return applyMiddleware(myRouterMiddleware, promiseMiddleware, localStorageMiddleware);14 } else {15 // Enable additional logging in non-production environments.16 return applyMiddleware(myRouterMiddleware, promiseMiddleware, localStorageMiddleware, createLogger())17 }18};19export const store = createStore(...
index.js
Source:index.js
1// @flow2import ResponseMiddleware from './response.middleware';3import authMiddleware from './auth.middleware';4import adminMiddleware from './admin.middleware';5import wrap from './wrap.middleware';6module.exports.ResponseMiddleware = ResponseMiddleware;7module.exports.authMiddleware = authMiddleware;8module.exports.adminMiddleware = adminMiddleware;...
Using AI Code Generation
1var express = require('express');2var app = express();3var request = require('request');4var bodyParser = require('body-parser');5var urlencodedParser = bodyParser.urlencoded({extended: false});6app.use(express.static('public'));7app.get('/index.html', function(req, res){8 res.sendFile(__dirname + "/" + "index.html");9});10app.post('/process_post', urlencodedParser, function(req, res){11 response = {12 };13 console.log(response);14 res.end(JSON.stringify(response));15});16app.get('/index2.html', function(req, res){17 res.sendFile(__dirname + "/" + "index2.html");18});19app.post('/process_post2', urlencodedParser, function(req, res){20 response = {21 };22 console.log(response);23 res.end(JSON.stringify(response));24});25app.get('/index3.html', function(req, res){26 res.sendFile(__dirname + "/" + "index3.html");27});28app.post('/process_post3', urlencodedParser, function(req, res){29 response = {30 };31 console.log(response);32 res.end(JSON.stringify(response));33});34app.get('/index4.html', function(req, res){35 res.sendFile(__dirname + "/" + "index4.html");36});37app.post('/process_post4', urlencodedParser, function(req, res){38 response = {39 };40 console.log(response);41 res.end(JSON.stringify(response));42});43app.get('/index5.html', function(req, res){44 res.sendFile(__dirname + "/" + "index5.html");45});46app.post('/process_post5', urlencodedParser, function(req, res){47 response = {48 };49 console.log(response);50 res.end(JSON.stringify(response
Using AI Code Generation
1const express = require('express');2const app = express();3app.use(express.static('public'));4app.get('/', (req, res) => {5 res.send('Hello World!');6});7app.get('/json', (req, res) => {8 res.json({ message: 'Hello json' });9});10app.get('/json2', (req, res) => {11 res.json({ message: 'Hello json2' });12});13app.get('/query', (req, res) => {14 console.log(req.query);15 res.send('Hello query');16});17app.get('/params/:id', (req, res) => {18 console.log(req.params);19 res.send('Hello params');20});21app.get('/search', (req, res) => {22 console.log(req.query);23 res.send('Hello search');24});25app.listen(8080, () => {26 console.log('Example app listening on port 8080!');27});28const express = require('express');29const app = express();30app.use(express.static('public'));31app.use((req, res, next) => {32 console.log(req.method, req.path, res.statusCode);33 next();34});35app.get('/', (req, res) => {36 res.send('Hello World!');37});38app.get('/json', (req, res) => {39 res.json({ message: 'Hello json' });40});41app.get('/json2', (req, res) => {42 res.json({ message: 'Hello json2' });43});44app.get('/query', (req, res) => {45 console.log(req.query);46 res.send('Hello query');47});48app.get('/params/:id', (req, res) => {49 console.log(req.params);50 res.send('Hello params');51});52app.get('/search', (req, res) => {53 console.log(req.query);54 res.send('Hello search');55});56app.listen(8080, () => {57 console.log('Example app listening on port 8080!');58});59const express = require('express');60const app = express();61app.use(express.static('public'));62app.use((req, res, next) => {63 console.log(req.method, req.path, res.statusCode);64 next();65});66app.get('/', (req, res) => {
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!