aboutsummaryrefslogtreecommitdiffhomepage
path: root/server.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server.ts')
-rw-r--r--server.ts32
1 files changed, 22 insertions, 10 deletions
diff --git a/server.ts b/server.ts
index dfaa8ad3d..110ae1ab8 100644
--- a/server.ts
+++ b/server.ts
@@ -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)
30import { logger } from './server/helpers/logger' 30import { logger } from './server/helpers/logger'
31import { API_VERSION, CONFIG, FILES_CACHE } from './server/initializers/constants' 31import { API_VERSION, FILES_CACHE, WEBSERVER, loadLanguages } from './server/initializers/constants'
32import { CONFIG } from './server/initializers/config'
32 33
33const missed = checkMissedConfig() 34const missed = checkMissedConfig()
34if (missed.length !== 0) { 35if (missed.length !== 0) {
@@ -78,6 +79,9 @@ migrate()
78 process.exit(-1) 79 process.exit(-1)
79 }) 80 })
80 81
82// ----------- Initialize -----------
83loadLanguages()
84
81// ----------- PeerTube modules ----------- 85// ----------- PeerTube modules -----------
82import { installApplication } from './server/initializers' 86import { installApplication } from './server/initializers'
83import { Emailer } from './server/lib/emailer' 87import { 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
125morgan.token('remote-addr', req => { 130morgan.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})
137morgan.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})
133morgan.token('user-agent', req => (req.get('DNT') === '1') ?
134 useragent.parse(req.get('user-agent')).family : req.get('user-agent'))
135app.use(morgan('combined', { 144app.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
139app.use(bodyParser.urlencoded({ extended: false })) 149app.use(bodyParser.urlencoded({ extended: false }))
140app.use(bodyParser.json({ 150app.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
149app.use(cookieParser()) 160app.use(cookieParser())
161
150// W3C DNT Tracking Status 162// W3C DNT Tracking Status
151app.use(advertiseDoNotTrack) 163app.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', () => {