X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server.ts;h=e3cddfd33a643a623cfa53932fc34adca138c673;hb=b87b606a65c9baa30742d74dd470945b08e17601;hp=e2ff6327b517061e906b285d0c98ae7f6f9f71bc;hpb=c6c0fa6cd8fe8f752463d8982c3dbcd448739c4e;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server.ts b/server.ts index e2ff6327b..e3cddfd33 100644 --- a/server.ts +++ b/server.ts @@ -20,7 +20,7 @@ import * as cli from 'commander' process.title = 'peertube' // Create our main app -const app = express() +const app = express().disable("x-powered-by") // ----------- Core checker ----------- import { checkMissedConfig, checkFFmpeg, checkNodeVersion } from './server/initializers/checker-before-init' @@ -121,7 +121,8 @@ import { updateStreamingPlaylistsInfohashesIfNeeded } from './server/lib/hls' import { PluginsCheckScheduler } from './server/lib/schedulers/plugins-check-scheduler' import { Hooks } from './server/lib/plugins/hooks' import { PluginManager } from './server/lib/plugins/plugin-manager' -import { LiveManager } from '@server/lib/live-manager' +import { LiveManager } from './server/lib/live-manager' +import { HttpStatusCode } from './shared/core-utils/miscs/http-error-codes' // ----------- Command line ----------- @@ -142,14 +143,14 @@ if (isTestInstance()) { } // For the logger -morgan.token('remote-addr', req => { +morgan.token('remote-addr', (req: express.Request) => { if (CONFIG.LOG.ANONYMIZE_IP === true || req.get('DNT') === '1') { return anonymize(req.ip, 16, 16) } return req.ip }) -morgan.token('user-agent', req => { +morgan.token('user-agent', (req: express.Request) => { if (req.get('DNT') === '1') { return useragent.parse(req.get('user-agent')).family } @@ -157,7 +158,8 @@ morgan.token('user-agent', req => { return req.get('user-agent') }) app.use(morgan('combined', { - stream: { write: logger.info.bind(logger) } + stream: { write: logger.info.bind(logger) }, + skip: req => CONFIG.LOG.LOG_PING_REQUESTS === false && req.originalUrl === '/api/v1/ping' })) // For body requests @@ -210,7 +212,7 @@ if (cli.client) app.use('/', clientsRouter) // Catch 404 and forward to error handler app.use(function (req, res, next) { const err = new Error('Not Found') - err['status'] = 404 + err['status'] = HttpStatusCode.NOT_FOUND_404 next(err) }) @@ -224,7 +226,7 @@ app.use(function (err, req, res, next) { const sql = err.parent ? err.parent.sql : undefined logger.error('Error in controller.', { err: error, sql }) - return res.status(err.status || 500).end() + return res.status(err.status || HttpStatusCode.INTERNAL_SERVER_ERROR_500).end() }) const server = createWebsocketTrackerServer(app) @@ -248,7 +250,7 @@ async function startApplication () { Emailer.Instance.init() await Promise.all([ - Emailer.Instance.checkConnectionOrDie(), + Emailer.Instance.checkConnection(), JobQueue.Instance.init() ]) @@ -282,7 +284,7 @@ async function startApplication () { // Make server listening server.listen(port, hostname, () => { - logger.info('Server listening on %s:%d', hostname, port) + logger.info('HTTP server listening on %s:%d', hostname, port) logger.info('Web server: %s', WEBSERVER.URL) Hooks.runAction('action:application.listening')