diff options
Diffstat (limited to 'server.ts')
-rw-r--r-- | server.ts | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -16,6 +16,8 @@ import * as morgan from 'morgan' | |||
16 | import * as cors from 'cors' | 16 | import * as cors from 'cors' |
17 | import * as cookieParser from 'cookie-parser' | 17 | import * as cookieParser from 'cookie-parser' |
18 | import * as helmet from 'helmet' | 18 | import * as helmet from 'helmet' |
19 | import * as useragent from 'useragent' | ||
20 | import * as anonymise from 'ip-anonymize' | ||
19 | 21 | ||
20 | process.title = 'peertube' | 22 | process.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) |
29 | import { logger } from './server/helpers/logger' | 31 | import { logger } from './server/helpers/logger' |
30 | import { API_VERSION, CONFIG, STATIC_PATHS, CACHE, REMOTE_SCHEME } from './server/initializers/constants' | 32 | import { API_VERSION, CONFIG, CACHE } from './server/initializers/constants' |
31 | 33 | ||
32 | const missed = checkMissedConfig() | 34 | const missed = checkMissedConfig() |
33 | if (missed.length !== 0) { | 35 | if (missed.length !== 0) { |
@@ -85,6 +87,7 @@ import { | |||
85 | trackerRouter, | 87 | trackerRouter, |
86 | createWebsocketServer | 88 | createWebsocketServer |
87 | } from './server/controllers' | 89 | } from './server/controllers' |
90 | import { advertiseDoNotTrack } from './server/middlewares/dnt' | ||
88 | import { Redis } from './server/lib/redis' | 91 | import { Redis } from './server/lib/redis' |
89 | import { BadActorFollowScheduler } from './server/lib/schedulers/bad-actor-follow-scheduler' | 92 | import { BadActorFollowScheduler } from './server/lib/schedulers/bad-actor-follow-scheduler' |
90 | import { RemoveOldJobsScheduler } from './server/lib/schedulers/remove-old-jobs-scheduler' | 93 | import { 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 |
110 | morgan.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 | }) | ||
118 | morgan.token('user-agent', req => (req.get('DNT') === '1') ? | ||
119 | useragent.parse(req.get('user-agent')).family : req.get('user-agent')) | ||
108 | app.use(morgan('combined', { | 120 | app.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 |
118 | app.use(cookieParser()) | 130 | app.use(cookieParser()) |
131 | // W3C DNT Tracking Status | ||
132 | app.use(advertiseDoNotTrack) | ||
119 | 133 | ||
120 | // ----------- Views, routes and static files ----------- | 134 | // ----------- Views, routes and static files ----------- |
121 | 135 | ||