diff options
author | Chocobozzz <me@florianbigard.com> | 2019-02-06 12:26:58 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-02-06 12:26:58 +0100 |
commit | 73471b1a52f242e86364ffb077ea6cadb3b07ae2 (patch) | |
tree | 43dbb7748e281f8d80f15326f489cdea10ec857d /server.ts | |
parent | c22419dd265c0c7185bf4197a1cb286eb3d8ebc0 (diff) | |
parent | f5305c04aae14467d6f957b713c5a902275cbb89 (diff) | |
download | PeerTube-73471b1a52f242e86364ffb077ea6cadb3b07ae2.tar.gz PeerTube-73471b1a52f242e86364ffb077ea6cadb3b07ae2.tar.zst PeerTube-73471b1a52f242e86364ffb077ea6cadb3b07ae2.zip |
Merge branch 'release/v1.2.0'
Diffstat (limited to 'server.ts')
-rw-r--r-- | server.ts | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -28,7 +28,7 @@ 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, CACHE, HTTP_SIGNATURE } from './server/initializers/constants' | 31 | import { API_VERSION, CONFIG, CACHE } from './server/initializers/constants' |
32 | 32 | ||
33 | const missed = checkMissedConfig() | 33 | const missed = checkMissedConfig() |
34 | if (missed.length !== 0) { | 34 | if (missed.length !== 0) { |
@@ -53,6 +53,9 @@ if (errorMessage !== null) { | |||
53 | app.set('trust proxy', CONFIG.TRUST_PROXY) | 53 | app.set('trust proxy', CONFIG.TRUST_PROXY) |
54 | 54 | ||
55 | // Security middleware | 55 | // Security middleware |
56 | import { baseCSP } from './server/middlewares' | ||
57 | |||
58 | app.use(baseCSP) | ||
56 | app.use(helmet({ | 59 | app.use(helmet({ |
57 | frameguard: { | 60 | frameguard: { |
58 | action: 'deny' // we only allow it for /videos/embed, see server/controllers/client.ts | 61 | action: 'deny' // we only allow it for /videos/embed, see server/controllers/client.ts |
@@ -87,16 +90,17 @@ import { | |||
87 | servicesRouter, | 90 | servicesRouter, |
88 | webfingerRouter, | 91 | webfingerRouter, |
89 | trackerRouter, | 92 | trackerRouter, |
90 | createWebsocketServer | 93 | createWebsocketTrackerServer, botsRouter |
91 | } from './server/controllers' | 94 | } from './server/controllers' |
92 | import { advertiseDoNotTrack } from './server/middlewares/dnt' | 95 | import { advertiseDoNotTrack } from './server/middlewares/dnt' |
93 | import { Redis } from './server/lib/redis' | 96 | import { Redis } from './server/lib/redis' |
94 | import { BadActorFollowScheduler } from './server/lib/schedulers/bad-actor-follow-scheduler' | 97 | import { ActorFollowScheduler } from './server/lib/schedulers/actor-follow-scheduler' |
95 | import { RemoveOldJobsScheduler } from './server/lib/schedulers/remove-old-jobs-scheduler' | 98 | import { RemoveOldJobsScheduler } from './server/lib/schedulers/remove-old-jobs-scheduler' |
96 | import { UpdateVideosScheduler } from './server/lib/schedulers/update-videos-scheduler' | 99 | import { UpdateVideosScheduler } from './server/lib/schedulers/update-videos-scheduler' |
97 | import { YoutubeDlUpdateScheduler } from './server/lib/schedulers/youtube-dl-update-scheduler' | 100 | import { YoutubeDlUpdateScheduler } from './server/lib/schedulers/youtube-dl-update-scheduler' |
98 | import { VideosRedundancyScheduler } from './server/lib/schedulers/videos-redundancy-scheduler' | 101 | import { VideosRedundancyScheduler } from './server/lib/schedulers/videos-redundancy-scheduler' |
99 | import { isHTTPSignatureDigestValid } from './server/helpers/peertube-crypto' | 102 | import { isHTTPSignatureDigestValid } from './server/helpers/peertube-crypto' |
103 | import { PeerTubeSocket } from './server/lib/peertube-socket' | ||
100 | 104 | ||
101 | // ----------- Command line ----------- | 105 | // ----------- Command line ----------- |
102 | 106 | ||
@@ -133,7 +137,7 @@ app.use(bodyParser.urlencoded({ extended: false })) | |||
133 | app.use(bodyParser.json({ | 137 | app.use(bodyParser.json({ |
134 | type: [ 'application/json', 'application/*+json' ], | 138 | type: [ 'application/json', 'application/*+json' ], |
135 | limit: '500kb', | 139 | limit: '500kb', |
136 | verify: (req: express.Request, _, buf: Buffer, encoding: string) => { | 140 | verify: (req: express.Request, _, buf: Buffer) => { |
137 | const valid = isHTTPSignatureDigestValid(buf, req) | 141 | const valid = isHTTPSignatureDigestValid(buf, req) |
138 | if (valid !== true) throw new Error('Invalid digest') | 142 | if (valid !== true) throw new Error('Invalid digest') |
139 | } | 143 | } |
@@ -156,6 +160,7 @@ app.use('/', activityPubRouter) | |||
156 | app.use('/', feedsRouter) | 160 | app.use('/', feedsRouter) |
157 | app.use('/', webfingerRouter) | 161 | app.use('/', webfingerRouter) |
158 | app.use('/', trackerRouter) | 162 | app.use('/', trackerRouter) |
163 | app.use('/', botsRouter) | ||
159 | 164 | ||
160 | // Static files | 165 | // Static files |
161 | app.use('/', staticRouter) | 166 | app.use('/', staticRouter) |
@@ -185,7 +190,7 @@ app.use(function (err, req, res, next) { | |||
185 | return res.status(err.status || 500).end() | 190 | return res.status(err.status || 500).end() |
186 | }) | 191 | }) |
187 | 192 | ||
188 | const server = createWebsocketServer(app) | 193 | const server = createWebsocketTrackerServer(app) |
189 | 194 | ||
190 | // ----------- Run ----------- | 195 | // ----------- Run ----------- |
191 | 196 | ||
@@ -215,7 +220,7 @@ async function startApplication () { | |||
215 | VideosCaptionCache.Instance.init(CONFIG.CACHE.VIDEO_CAPTIONS.SIZE, CACHE.VIDEO_CAPTIONS.MAX_AGE) | 220 | VideosCaptionCache.Instance.init(CONFIG.CACHE.VIDEO_CAPTIONS.SIZE, CACHE.VIDEO_CAPTIONS.MAX_AGE) |
216 | 221 | ||
217 | // Enable Schedulers | 222 | // Enable Schedulers |
218 | BadActorFollowScheduler.Instance.enable() | 223 | ActorFollowScheduler.Instance.enable() |
219 | RemoveOldJobsScheduler.Instance.enable() | 224 | RemoveOldJobsScheduler.Instance.enable() |
220 | UpdateVideosScheduler.Instance.enable() | 225 | UpdateVideosScheduler.Instance.enable() |
221 | YoutubeDlUpdateScheduler.Instance.enable() | 226 | YoutubeDlUpdateScheduler.Instance.enable() |
@@ -224,6 +229,8 @@ async function startApplication () { | |||
224 | // Redis initialization | 229 | // Redis initialization |
225 | Redis.Instance.init() | 230 | Redis.Instance.init() |
226 | 231 | ||
232 | PeerTubeSocket.Instance.init(server) | ||
233 | |||
227 | // Make server listening | 234 | // Make server listening |
228 | server.listen(port, hostname, () => { | 235 | server.listen(port, hostname, () => { |
229 | logger.info('Server listening on %s:%d', hostname, port) | 236 | logger.info('Server listening on %s:%d', hostname, port) |