diff options
Diffstat (limited to 'server.ts')
-rw-r--r-- | server.ts | 39 |
1 files changed, 6 insertions, 33 deletions
@@ -10,13 +10,8 @@ if (isTestInstance()) { | |||
10 | // ----------- Node modules ----------- | 10 | // ----------- Node modules ----------- |
11 | import * as bodyParser from 'body-parser' | 11 | import * as bodyParser from 'body-parser' |
12 | import * as express from 'express' | 12 | import * as express from 'express' |
13 | import * as http from 'http' | ||
14 | import * as morgan from 'morgan' | 13 | import * as morgan from 'morgan' |
15 | import * as bitTorrentTracker from 'bittorrent-tracker' | ||
16 | import * as cors from 'cors' | 14 | import * as cors from 'cors' |
17 | import { Server as WebSocketServer } from 'ws' | ||
18 | |||
19 | const TrackerServer = bitTorrentTracker.Server | ||
20 | 15 | ||
21 | process.title = 'peertube' | 16 | process.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' |
80 | import { Redis } from './server/lib/redis' | 77 | import { Redis } from './server/lib/redis' |
81 | import { BadActorFollowScheduler } from './server/lib/schedulers/bad-actor-follow-scheduler' | 78 | import { 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 | |||
121 | const trackerServer = new TrackerServer({ | ||
122 | http: false, | ||
123 | udp: false, | ||
124 | ws: false, | ||
125 | dht: false | ||
126 | }) | ||
127 | |||
128 | trackerServer.on('error', function (err) { | ||
129 | logger.error('Error in websocket tracker.', err) | ||
130 | }) | ||
131 | |||
132 | trackerServer.on('warning', function (err) { | ||
133 | logger.error('Warning in websocket tracker.', err) | ||
134 | }) | ||
135 | |||
136 | const server = http.createServer(app) | ||
137 | const wss = new WebSocketServer({ server: server, path: '/tracker/socket' }) | ||
138 | wss.on('connection', function (ws) { | ||
139 | trackerServer.onWebSocketConnection(ws) | ||
140 | }) | ||
141 | |||
142 | const onHttpRequest = trackerServer.onHttpRequest.bind(trackerServer) | ||
143 | app.get('/tracker/announce', (req, res) => onHttpRequest(req, res, { action: 'announce' })) | ||
144 | app.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) | |||
155 | app.use('/', activityPubRouter) | 125 | app.use('/', activityPubRouter) |
156 | app.use('/', feedsRouter) | 126 | app.use('/', feedsRouter) |
157 | app.use('/', webfingerRouter) | 127 | app.use('/', webfingerRouter) |
128 | app.use('/', trackerRouter) | ||
158 | 129 | ||
159 | // Static files | 130 | // Static files |
160 | app.use('/', staticRouter) | 131 | app.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 | ||
155 | const server = createWebsocketServer(app) | ||
156 | |||
184 | // ----------- Run ----------- | 157 | // ----------- Run ----------- |
185 | 158 | ||
186 | async function startApplication () { | 159 | async function startApplication () { |