aboutsummaryrefslogtreecommitdiffhomepage
path: root/server.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server.ts')
-rw-r--r--server.ts18
1 files changed, 16 insertions, 2 deletions
diff --git a/server.ts b/server.ts
index 9094ac943..eccd19919 100644
--- a/server.ts
+++ b/server.ts
@@ -16,6 +16,8 @@ import * as morgan from 'morgan'
16import * as cors from 'cors' 16import * as cors from 'cors'
17import * as cookieParser from 'cookie-parser' 17import * as cookieParser from 'cookie-parser'
18import * as helmet from 'helmet' 18import * as helmet from 'helmet'
19import * as useragent from 'useragent'
20import * as anonymise from 'ip-anonymize'
19 21
20process.title = 'peertube' 22process.title = 'peertube'
21 23
@@ -27,7 +29,7 @@ import { checkMissedConfig, checkFFmpeg, checkConfig, checkActivityPubUrls } fro
27 29
28// Do not use barrels because we don't want to load all modules here (we need to initialize database first) 30// Do not use barrels because we don't want to load all modules here (we need to initialize database first)
29import { logger } from './server/helpers/logger' 31import { logger } from './server/helpers/logger'
30import { API_VERSION, CONFIG, STATIC_PATHS, CACHE, REMOTE_SCHEME } from './server/initializers/constants' 32import { API_VERSION, CONFIG, CACHE } from './server/initializers/constants'
31 33
32const missed = checkMissedConfig() 34const missed = checkMissedConfig()
33if (missed.length !== 0) { 35if (missed.length !== 0) {
@@ -85,6 +87,7 @@ import {
85 trackerRouter, 87 trackerRouter,
86 createWebsocketServer 88 createWebsocketServer
87} from './server/controllers' 89} from './server/controllers'
90import { advertiseDoNotTrack } from './server/middlewares/dnt'
88import { Redis } from './server/lib/redis' 91import { Redis } from './server/lib/redis'
89import { BadActorFollowScheduler } from './server/lib/schedulers/bad-actor-follow-scheduler' 92import { BadActorFollowScheduler } from './server/lib/schedulers/bad-actor-follow-scheduler'
90import { RemoveOldJobsScheduler } from './server/lib/schedulers/remove-old-jobs-scheduler' 93import { RemoveOldJobsScheduler } from './server/lib/schedulers/remove-old-jobs-scheduler'
@@ -103,8 +106,17 @@ if (isTestInstance()) {
103 credentials: true 106 credentials: true
104 })) 107 }))
105} 108}
106
107// For the logger 109// For the logger
110morgan.token('remote-addr', req => {
111 return (req.get('DNT') === '1') ?
112 anonymise(req.ip || (req.connection && req.connection.remoteAddress) || undefined,
113 16, // bitmask for IPv4
114 16 // bitmask for IPv6
115 ) :
116 req.ip
117})
118morgan.token('user-agent', req => (req.get('DNT') === '1') ?
119 useragent.parse(req.get('user-agent')).family : req.get('user-agent'))
108app.use(morgan('combined', { 120app.use(morgan('combined', {
109 stream: { write: logger.info.bind(logger) } 121 stream: { write: logger.info.bind(logger) }
110})) 122}))
@@ -116,6 +128,8 @@ app.use(bodyParser.json({
116})) 128}))
117// Cookies 129// Cookies
118app.use(cookieParser()) 130app.use(cookieParser())
131// W3C DNT Tracking Status
132app.use(advertiseDoNotTrack)
119 133
120// ----------- Views, routes and static files ----------- 134// ----------- Views, routes and static files -----------
121 135