aboutsummaryrefslogtreecommitdiffhomepage
path: root/server.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server.ts')
-rw-r--r--server.ts19
1 files changed, 13 insertions, 6 deletions
diff --git a/server.ts b/server.ts
index 3025a6fd7..b50151859 100644
--- a/server.ts
+++ b/server.ts
@@ -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)
30import { logger } from './server/helpers/logger' 30import { logger } from './server/helpers/logger'
31import { API_VERSION, CONFIG, CACHE, HTTP_SIGNATURE } from './server/initializers/constants' 31import { API_VERSION, CONFIG, CACHE } from './server/initializers/constants'
32 32
33const missed = checkMissedConfig() 33const missed = checkMissedConfig()
34if (missed.length !== 0) { 34if (missed.length !== 0) {
@@ -53,6 +53,9 @@ if (errorMessage !== null) {
53app.set('trust proxy', CONFIG.TRUST_PROXY) 53app.set('trust proxy', CONFIG.TRUST_PROXY)
54 54
55// Security middleware 55// Security middleware
56import { baseCSP } from './server/middlewares'
57
58app.use(baseCSP)
56app.use(helmet({ 59app.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'
92import { advertiseDoNotTrack } from './server/middlewares/dnt' 95import { advertiseDoNotTrack } from './server/middlewares/dnt'
93import { Redis } from './server/lib/redis' 96import { Redis } from './server/lib/redis'
94import { BadActorFollowScheduler } from './server/lib/schedulers/bad-actor-follow-scheduler' 97import { ActorFollowScheduler } from './server/lib/schedulers/actor-follow-scheduler'
95import { RemoveOldJobsScheduler } from './server/lib/schedulers/remove-old-jobs-scheduler' 98import { RemoveOldJobsScheduler } from './server/lib/schedulers/remove-old-jobs-scheduler'
96import { UpdateVideosScheduler } from './server/lib/schedulers/update-videos-scheduler' 99import { UpdateVideosScheduler } from './server/lib/schedulers/update-videos-scheduler'
97import { YoutubeDlUpdateScheduler } from './server/lib/schedulers/youtube-dl-update-scheduler' 100import { YoutubeDlUpdateScheduler } from './server/lib/schedulers/youtube-dl-update-scheduler'
98import { VideosRedundancyScheduler } from './server/lib/schedulers/videos-redundancy-scheduler' 101import { VideosRedundancyScheduler } from './server/lib/schedulers/videos-redundancy-scheduler'
99import { isHTTPSignatureDigestValid } from './server/helpers/peertube-crypto' 102import { isHTTPSignatureDigestValid } from './server/helpers/peertube-crypto'
103import { 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 }))
133app.use(bodyParser.json({ 137app.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)
156app.use('/', feedsRouter) 160app.use('/', feedsRouter)
157app.use('/', webfingerRouter) 161app.use('/', webfingerRouter)
158app.use('/', trackerRouter) 162app.use('/', trackerRouter)
163app.use('/', botsRouter)
159 164
160// Static files 165// Static files
161app.use('/', staticRouter) 166app.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
188const server = createWebsocketServer(app) 193const 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)