app.ready().then(() => { console.log('app(%s) ready', app.config.baseDir); const server = http.createServer(app.callback()); // emit server event just like egg-cluster does // https://github.com/eggjs/egg-cluster/blob/master/lib/app_worker.js#L52 app.emit('server', server); server.listen(7001, () => { console.log('Server started at 7001'); }); });
// Initializes the server and mounts it in the generated build directory. http.createServer((req, res) => { // If we are accessing the root, it should be redirected to the default language, // We shouldn't get a 404 page. if (req.url === '/') { req.url = `/${mainLocale}` } mount(req, res) }).listen(port, () => { console.log(`\x1B[32mServer running at http://localhost:${port}/${mainLocale}/\x1B[39m`) })
listen (callback) { const self = this this.server.listen(0, '127.0.0.1', function () { self.uploadUrl = `http://127.0.0.1:${self.server.address().port}` callback() }) }
test('upload - bad response', function (t) { const dataDirectory = path.resolve( __dirname, 'fixtures', 'only-folder', '10000.clinic-doctor' ) const server = http.createServer(function (req, res) { res.destroy() }) server.listen(0, '127.0.0.1', function () { const uploadUrl = `http://localhost:${server.address().port}` tarAndUpload(dataDirectory, uploadUrl, null, {}, function (err) { t.strictEqual(err.message, 'socket hang up') server.close(() => t.end()) }) }) })
function startProxyServer() { const port = 3123; const requestHandler = (request, response) => { response.writeHead(200, { "Content-Type": "application/json" }); response.end( JSON.stringify({ path: request.url }) ); }; const server = http.createServer(requestHandler); server.listen(port, err => { if (err) { return console.log("something bad happened", err); } }); return server; }
/** * Initialize reporter * @param {MetricRegistry} registry * @memberof PrometheusReporter */ init(registry) { super.init(registry); this.server = http.createServer(); this.server.on("request", this.handler.bind(this)); this.server.listen(this.opts.port, err => { if (err) { /* istanbul ignore next */ return this.registry.broker.fatal(new MoleculerError("Prometheus metric reporter listening error: " + err.message)); } this.logger.info(`Prometheus metric reporter listening on http://0.0.0.0:${this.opts.port}${this.opts.path} address.`); }); this.defaultLabels = isFunction(this.opts.defaultLabels) ? this.opts.defaultLabels.call(this, registry) : this.opts.defaultLabels; }
server.listen(port, () => { console.log(`🚀 Cube.js server (${CubejsServerCore.version()}) is listening on ${port}`); });
test('clinic upload - bad status code', function (t) { const server = http.createServer(function (req, res) { res.statusCode = 500 res.end() }) server.listen(function () { cli({ env: { CLINIC_JWT: successfulJwt }, relayStderr: false }, [ 'clinic', 'upload', '--server', `http://127.0.0.1:${server.address().port}`, '--no-open', doctorADirectory ], function (err, stdout, stderr) { t.strictDeepEqual(err, new Error('process exited with exit code 1')) t.strictDeepEqual(stdout.trim().split('\n'), [ 'Signed in as test@test.com.', `Uploading data for ${doctorADirectory} and ${doctorADirectory}.html` ]) t.ok(stderr.includes('Bad status code: 500')) server.close(() => t.end()) }) }) })
server.listen(process.env.PORT || 3000, function onListen() { var address = server.address(); console.log('Listening on: %j', address); console.log(' -> that probably means: http://localhost:%d', address.port); });
test('upload - error message from server', function (t) { const dataDirectory = path.resolve( __dirname, 'fixtures', 'only-folder', '10000.clinic-doctor' ) const server = http.createServer(function (req, res) { res.statusCode = 400 res.end('{"statusCode": 400, "error": "Bad Request", "message": "This is the message"}') }) server.listen(0, '127.0.0.1', function () { const uploadUrl = `http://localhost:${server.address().port}` tarAndUpload(dataDirectory, uploadUrl, null, {}, function (err) { t.strictDeepEqual(err, Object.assign(new Error('This is the message'), { reply: { statusCode: 400, error: 'Bad Request', message: 'This is the message' } })) server.close(() => t.end()) }) }) })
http.listen(port, function () { console.log("http://localhost:" + port); });
test('upload - bad status code', function (t) { const dataDirectory = path.resolve( __dirname, 'fixtures', 'only-folder', '10000.clinic-doctor' ) const server = http.createServer(function (req, res) { res.statusCode = 500 res.end() }) server.listen(0, '127.0.0.1', function () { const uploadUrl = `http://localhost:${server.address().port}` tarAndUpload(dataDirectory, uploadUrl, null, {}, function (err) { t.strictDeepEqual(err, new Error('Bad status code: 500')) server.close(() => t.end()) }) }) })
test('upload - bad body encoding', function (t) { const dataDirectory = path.resolve( __dirname, 'fixtures', 'only-folder', '10000.clinic-doctor' ) const server = http.createServer(function (req, res) { res.end('not JSON') }) server.listen(0, '127.0.0.1', function () { const uploadUrl = `http://localhost:${server.address().port}` tarAndUpload(dataDirectory, uploadUrl, null, {}, function (err) { t.strictEqual(err.name, 'SyntaxError') server.close(() => t.end()) }) }) })
server.listen(port, () => { console.log(`🚀 Cube.js server (${CubejsServerCore.version()}) is listening on ${port}`); });
function startProxyServer() { const port = 3123; const requestHandler = (request, response) => { response.writeHead(200, { "Content-Type": "application/json" }); response.end( JSON.stringify({ path: request.url }) ); }; const server = http.createServer(requestHandler); server.listen(port, err => { if (err) { return console.log("something bad happened", err); } }); return server; }