aboutsummaryrefslogtreecommitdiffhomepage
path: root/server.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server.ts')
-rw-r--r--server.ts39
1 files changed, 6 insertions, 33 deletions
diff --git a/server.ts b/server.ts
index f756bf9d4..fb01ed572 100644
--- a/server.ts
+++ b/server.ts
@@ -10,13 +10,8 @@ if (isTestInstance()) {
10// ----------- Node modules ----------- 10// ----------- Node modules -----------
11import * as bodyParser from 'body-parser' 11import * as bodyParser from 'body-parser'
12import * as express from 'express' 12import * as express from 'express'
13import * as http from 'http'
14import * as morgan from 'morgan' 13import * as morgan from 'morgan'
15import * as bitTorrentTracker from 'bittorrent-tracker'
16import * as cors from 'cors' 14import * as cors from 'cors'
17import { Server as WebSocketServer } from 'ws'
18
19const TrackerServer = bitTorrentTracker.Server
20 15
21process.title = 'peertube' 16process.title = 'peertube'
22 17
@@ -75,7 +70,9 @@ import {
75 feedsRouter, 70 feedsRouter,
76 staticRouter, 71 staticRouter,
77 servicesRouter, 72 servicesRouter,
78 webfingerRouter 73 webfingerRouter,
74 trackerRouter,
75 createWebsocketServer
79} from './server/controllers' 76} from './server/controllers'
80import { Redis } from './server/lib/redis' 77import { Redis } from './server/lib/redis'
81import { BadActorFollowScheduler } from './server/lib/schedulers/bad-actor-follow-scheduler' 78import { BadActorFollowScheduler } from './server/lib/schedulers/bad-actor-follow-scheduler'
@@ -116,33 +113,6 @@ app.use(bodyParser.json({
116 limit: '500kb' 113 limit: '500kb'
117})) 114}))
118 115
119// ----------- Tracker -----------
120
121const trackerServer = new TrackerServer({
122 http: false,
123 udp: false,
124 ws: false,
125 dht: false
126})
127
128trackerServer.on('error', function (err) {
129 logger.error('Error in websocket tracker.', err)
130})
131
132trackerServer.on('warning', function (err) {
133 logger.error('Warning in websocket tracker.', err)
134})
135
136const server = http.createServer(app)
137const wss = new WebSocketServer({ server: server, path: '/tracker/socket' })
138wss.on('connection', function (ws) {
139 trackerServer.onWebSocketConnection(ws)
140})
141
142const onHttpRequest = trackerServer.onHttpRequest.bind(trackerServer)
143app.get('/tracker/announce', (req, res) => onHttpRequest(req, res, { action: 'announce' }))
144app.get('/tracker/scrape', (req, res) => onHttpRequest(req, res, { action: 'scrape' }))
145
146// ----------- Views, routes and static files ----------- 116// ----------- Views, routes and static files -----------
147 117
148// API 118// API
@@ -155,6 +125,7 @@ app.use('/services', servicesRouter)
155app.use('/', activityPubRouter) 125app.use('/', activityPubRouter)
156app.use('/', feedsRouter) 126app.use('/', feedsRouter)
157app.use('/', webfingerRouter) 127app.use('/', webfingerRouter)
128app.use('/', trackerRouter)
158 129
159// Static files 130// Static files
160app.use('/', staticRouter) 131app.use('/', staticRouter)
@@ -181,6 +152,8 @@ app.use(function (err, req, res, next) {
181 return res.status(err.status || 500).end() 152 return res.status(err.status || 500).end()
182}) 153})
183 154
155const server = createWebsocketServer(app)
156
184// ----------- Run ----------- 157// ----------- Run -----------
185 158
186async function startApplication () { 159async function startApplication () {