diff options
Diffstat (limited to 'server.ts')
-rw-r--r-- | server.ts | 32 |
1 files changed, 22 insertions, 10 deletions
@@ -28,7 +28,8 @@ import { checkMissedConfig, checkFFmpeg } from './server/initializers/checker-be | |||
28 | 28 | ||
29 | // Do not use barrels because we don't want to load all modules here (we need to initialize database first) | 29 | // Do not use barrels because we don't want to load all modules here (we need to initialize database first) |
30 | import { logger } from './server/helpers/logger' | 30 | import { logger } from './server/helpers/logger' |
31 | import { API_VERSION, CONFIG, FILES_CACHE } from './server/initializers/constants' | 31 | import { API_VERSION, FILES_CACHE, WEBSERVER, loadLanguages } from './server/initializers/constants' |
32 | import { CONFIG } from './server/initializers/config' | ||
32 | 33 | ||
33 | const missed = checkMissedConfig() | 34 | const missed = checkMissedConfig() |
34 | if (missed.length !== 0) { | 35 | if (missed.length !== 0) { |
@@ -78,6 +79,9 @@ migrate() | |||
78 | process.exit(-1) | 79 | process.exit(-1) |
79 | }) | 80 | }) |
80 | 81 | ||
82 | // ----------- Initialize ----------- | ||
83 | loadLanguages() | ||
84 | |||
81 | // ----------- PeerTube modules ----------- | 85 | // ----------- PeerTube modules ----------- |
82 | import { installApplication } from './server/initializers' | 86 | import { installApplication } from './server/initializers' |
83 | import { Emailer } from './server/lib/emailer' | 87 | import { Emailer } from './server/lib/emailer' |
@@ -121,20 +125,26 @@ if (isTestInstance()) { | |||
121 | credentials: true | 125 | credentials: true |
122 | })) | 126 | })) |
123 | } | 127 | } |
128 | |||
124 | // For the logger | 129 | // For the logger |
125 | morgan.token('remote-addr', req => { | 130 | morgan.token('remote-addr', req => { |
126 | return (req.get('DNT') === '1') ? | 131 | if (req.get('DNT') === '1') { |
127 | anonymize(req.ip || (req.connection && req.connection.remoteAddress) || undefined, | 132 | return anonymize(req.ip, 16, 16) |
128 | 16, // bitmask for IPv4 | 133 | } |
129 | 16 // bitmask for IPv6 | 134 | |
130 | ) : | 135 | return req.ip |
131 | req.ip | 136 | }) |
137 | morgan.token('user-agent', req => { | ||
138 | if (req.get('DNT') === '1') { | ||
139 | return useragent.parse(req.get('user-agent')).family | ||
140 | } | ||
141 | |||
142 | return req.get('user-agent') | ||
132 | }) | 143 | }) |
133 | morgan.token('user-agent', req => (req.get('DNT') === '1') ? | ||
134 | useragent.parse(req.get('user-agent')).family : req.get('user-agent')) | ||
135 | app.use(morgan('combined', { | 144 | app.use(morgan('combined', { |
136 | stream: { write: logger.info.bind(logger) } | 145 | stream: { write: logger.info.bind(logger) } |
137 | })) | 146 | })) |
147 | |||
138 | // For body requests | 148 | // For body requests |
139 | app.use(bodyParser.urlencoded({ extended: false })) | 149 | app.use(bodyParser.urlencoded({ extended: false })) |
140 | app.use(bodyParser.json({ | 150 | app.use(bodyParser.json({ |
@@ -145,8 +155,10 @@ app.use(bodyParser.json({ | |||
145 | if (valid !== true) throw new Error('Invalid digest') | 155 | if (valid !== true) throw new Error('Invalid digest') |
146 | } | 156 | } |
147 | })) | 157 | })) |
158 | |||
148 | // Cookies | 159 | // Cookies |
149 | app.use(cookieParser()) | 160 | app.use(cookieParser()) |
161 | |||
150 | // W3C DNT Tracking Status | 162 | // W3C DNT Tracking Status |
151 | app.use(advertiseDoNotTrack) | 163 | app.use(advertiseDoNotTrack) |
152 | 164 | ||
@@ -240,7 +252,7 @@ async function startApplication () { | |||
240 | // Make server listening | 252 | // Make server listening |
241 | server.listen(port, hostname, () => { | 253 | server.listen(port, hostname, () => { |
242 | logger.info('Server listening on %s:%d', hostname, port) | 254 | logger.info('Server listening on %s:%d', hostname, port) |
243 | logger.info('Web server: %s', CONFIG.WEBSERVER.URL) | 255 | logger.info('Web server: %s', WEBSERVER.URL) |
244 | }) | 256 | }) |
245 | 257 | ||
246 | process.on('exit', () => { | 258 | process.on('exit', () => { |