function startMockServer(port, options = {}) { assert.ok(port); const server = http.Server((req, res) => { servers[port].polling = true; if (options.bad) { return res.end('can not be parsed with JSON.parse()'); } return res.end(JSON.stringify({ ok: true, result: [{ update_id: 0, message: { text: 'test' }, }], })); }); return new Promise((resolve, reject) => { servers[port] = { server, polling: false }; server.on('error', reject).listen(port, resolve); }); }
describe('#api', function () { it('#start()', function (done) { var server = new Proxy(8848); server.start().then(function () { if (server.httpServer instanceof http.Server) { done(); } else { done(new Error('server.httpServer is not an instance of http.Server')); } server.stop(); }); }); });
constructor(){ this.port = process.env.PORT || 3000; this.host = `localhost`; this.app = express(); this.http = http.Server(this.app); this.socket = socketio(this.http); }
// Worker processes have a http server. http.Server((req, res) => { var pathname = url.parse(req.url).pathname; console.log("\nRequest for " + pathname + " received."); console.log(`Request method: ${req.method}`); // console.log(`Headers ${JSON.stringify(req.headers)}`); res.writeHead(200); res.end(`hello world from worker ${cluster.worker.id} \n`); // notify master about the request process.send({ cmd: 'notifyRequest', workerId:cluster.worker.id, workerPid: process.pid, isMasterProcess: cluster.isMaster}); }).listen(8080);
constructor() { this.app = express(); this.http = http.Server(this.app); }
parentPort.on('message', (value) => { assert(value.hereIsYourPort instanceof MessagePort); const myParentPort = value.hereIsYourPort; console.log(`${threadId}: received parentPort: ${JSON.stringify(myParentPort)}`) myParentPort.postMessage(`The worker Id: ${threadId} is sending this.`); // Worker processes have a http server. http.Server((req, res) => { var pathname = url.parse(req.url).pathname; console.log("\nRequest for " + pathname + " received."); console.log(`Request method: ${req.method}`); // console.log(`Headers ${JSON.stringify(req.headers)}`); res.writeHead(200); res.end(workerData.message); // notify master about the request const message = { cmd: 'notifyRequest', workerId: threadId, isMain: isMainThread}; console.log(message); // myParentPort.postMessage(message); parentPort.postMessage(message); }).listen(workerData.port); });
function createServer (app) { const server = http.Server(app) app.server = server return server }
// Create HTTP server. http.Server(function(req, res) { res.writeHead(200); res.end("This answer comes from the process " + process.pid); //that's just for example while(true){ } }).listen(8080);
const server = http.Server(app) const io = socketio(server) const connectedUsers = {}
it('should start server (attached via app.use directly)',function(done){ done = _.once(done); var doneTick = _.after(3,done); // Create Express Application app = express(); // Make HTTP2 work with Express expressHTTP2WorkaroundMiddleware = expressHTTP2Workaround({ express:express, http2:http2 }); app.use(expressHTTP2WorkaroundMiddleware); // Setup HTTP/1.x Server httpServer = http.Server(app); httpServer.listen(httpPort,function(){ doneTick(); }); // Setup HTTP/2 Server http2Server = http2.createServer(httpsOptions,app); http2Server.listen(httpsPort,function(){ doneTick(); }); // Serve some content app.get('/', function(req,res){ try{ res.send('HTTP:'+req.httpVersion); if(resDoneHandler) resDoneHandler(false); }catch(err){ if(resDoneHandler) resDoneHandler(err); } try{ res.end(); }catch(err){} }); doneTick(); });
}) var server = new http.Server(onRequest(t)) sendRequest(server) }) }) var server = new http.Server() server.addListener('request', onRequest(t)) sendRequest(server) }) var server = new http.Server() server.on('request', onRequest(t)) sendRequest(server) }) var server = new http.Server() server.on('request', onRequest(t, true)) sendRequest(server, undefined, true)
httpServer = http.Server(app); httpServer.listen(httpPort,function(){ doneTick();
// Worker processes have a http server. http.Server( (req, res) => { res.writeHead(200); res.end("hello world\n"); process.send({ cmd: 'notifyRequest' }); }).listen(8000);
constructor() { this.app = express(); this.http = http.Server(this.app); }