X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server.ts;h=b307e67a1df71ee2924f2f492bd40db69c85770e;hb=20760d9160e09bb4efaddffb331395f8d6c3c59d;hp=dc7a71d608c2555e9edb648581234c7b8804ced7;hpb=1e9d7b60cd93ad5d1aed47fd157f1993d4b4eac0;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server.ts b/server.ts index dc7a71d60..b307e67a1 100644 --- a/server.ts +++ b/server.ts @@ -27,22 +27,31 @@ const app = express() // ----------- Core checker ----------- import { checkMissedConfig, checkFFmpeg, checkConfig } from './server/initializers/checker' +// Do not use barrels because we don't want to load all modules here (we need to initialize database first) +import { logger } from './server/helpers/logger' +import { ACCEPT_HEADERS, API_VERSION, CONFIG, STATIC_PATHS } from './server/initializers/constants' + const missed = checkMissedConfig() if (missed.length !== 0) { - throw new Error('Your configuration files miss keys: ' + missed) + logger.error('Your configuration files miss keys: ' + missed) + process.exit(-1) } -import { ACCEPT_HEADERS, API_VERSION, CONFIG, STATIC_PATHS } from './server/initializers/constants' checkFFmpeg(CONFIG) + .catch(err => { + logger.error('Error in ffmpeg check.', { err }) + process.exit(-1) + }) const errorMessage = checkConfig() if (errorMessage !== null) { throw new Error(errorMessage) } +// Trust our proxy (IP forwarding...) +app.set('trust proxy', CONFIG.TRUST_PROXY) + // ----------- Database ----------- -// Do not use barrels because we don't want to load all modules here (we need to initialize database first) -import { logger } from './server/helpers/logger' // Initialize database and models import { initDatabaseModels } from './server/initializers/database' @@ -75,6 +84,7 @@ if (isTestInstance()) { ) { return (cors({ origin: 'http://localhost:3000', + exposedHeaders: 'Retry-After', credentials: true }))(req, res, next) } @@ -88,11 +98,11 @@ app.use(morgan('combined', { stream: { write: logger.info.bind(logger) } })) // For body requests +app.use(bodyParser.urlencoded({ extended: false })) app.use(bodyParser.json({ type: [ 'application/json', 'application/*+json' ], limit: '500kb' })) -app.use(bodyParser.urlencoded({ extended: false })) // ----------- Tracker ----------- @@ -158,8 +168,13 @@ app.use(function (req, res, next) { }) app.use(function (err, req, res, next) { - logger.error(err, err) - res.sendStatus(err.status || 500) + let error = 'Unknown error.' + if (err) { + error = err.stack || err.message || err + } + + logger.error('Error in controller.', { error }) + return res.status(err.status || 500).end() }) // ----------- Run -----------