X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server.ts;h=a7fea34da83d07599131f7f3d18968ef87a6db6a;hb=16f7022b06fb76c0b00c23c970bc8df605b0ec63;hp=ef89ff5f653dad11ef915af1dc13efc3c0e4032c;hpb=2baea0c77cc765f7cbca9c9a2f4272268892a35c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server.ts b/server.ts index ef89ff5f6..a7fea34da 100644 --- a/server.ts +++ b/server.ts @@ -1,5 +1,5 @@ // FIXME: https://github.com/nodejs/node/pull/16853 -import { ScheduleVideoUpdateModel } from './server/models/video/schedule-video-update' +import { VideosCaptionCache } from './server/lib/cache/videos-caption-cache' require('tls').DEFAULT_ECDH_CURVE = 'auto' @@ -12,13 +12,9 @@ if (isTestInstance()) { // ----------- Node modules ----------- import * as bodyParser from 'body-parser' import * as express from 'express' -import * as http from 'http' import * as morgan from 'morgan' -import * as bitTorrentTracker from 'bittorrent-tracker' import * as cors from 'cors' -import { Server as WebSocketServer } from 'ws' - -const TrackerServer = bitTorrentTracker.Server +import * as cookieParser from 'cookie-parser' process.title = 'peertube' @@ -26,7 +22,7 @@ process.title = 'peertube' const app = express() // ----------- Core checker ----------- -import { checkMissedConfig, checkFFmpeg, checkConfig } from './server/initializers/checker' +import { checkMissedConfig, checkFFmpeg, checkConfig, checkActivityPubUrls } from './server/initializers/checker' // Do not use barrels because we don't want to load all modules here (we need to initialize database first) import { logger } from './server/helpers/logger' @@ -77,7 +73,9 @@ import { feedsRouter, staticRouter, servicesRouter, - webfingerRouter + webfingerRouter, + trackerRouter, + createWebsocketServer } from './server/controllers' import { Redis } from './server/lib/redis' import { BadActorFollowScheduler } from './server/lib/schedulers/bad-actor-follow-scheduler' @@ -94,7 +92,8 @@ if (isTestInstance()) { // These routes have already cors if ( req.path.indexOf(STATIC_PATHS.TORRENTS) === -1 && - req.path.indexOf(STATIC_PATHS.WEBSEED) === -1 + req.path.indexOf(STATIC_PATHS.WEBSEED) === -1 && + req.path.startsWith('/api/') === false ) { return (cors({ origin: '*', @@ -117,33 +116,8 @@ app.use(bodyParser.json({ type: [ 'application/json', 'application/*+json' ], limit: '500kb' })) - -// ----------- Tracker ----------- - -const trackerServer = new TrackerServer({ - http: false, - udp: false, - ws: false, - dht: false -}) - -trackerServer.on('error', function (err) { - logger.error('Error in websocket tracker.', err) -}) - -trackerServer.on('warning', function (err) { - logger.error('Warning in websocket tracker.', err) -}) - -const server = http.createServer(app) -const wss = new WebSocketServer({ server: server, path: '/tracker/socket' }) -wss.on('connection', function (ws) { - trackerServer.onWebSocketConnection(ws) -}) - -const onHttpRequest = trackerServer.onHttpRequest.bind(trackerServer) -app.get('/tracker/announce', (req, res) => onHttpRequest(req, res, { action: 'announce' })) -app.get('/tracker/scrape', (req, res) => onHttpRequest(req, res, { action: 'scrape' })) +// Cookies +app.use(cookieParser()) // ----------- Views, routes and static files ----------- @@ -157,6 +131,7 @@ app.use('/services', servicesRouter) app.use('/', activityPubRouter) app.use('/', feedsRouter) app.use('/', webfingerRouter) +app.use('/', trackerRouter) // Static files app.use('/', staticRouter) @@ -183,6 +158,8 @@ app.use(function (err, req, res, next) { return res.status(err.status || 500).end() }) +const server = createWebsocketServer(app) + // ----------- Run ----------- async function startApplication () { @@ -191,6 +168,13 @@ async function startApplication () { await installApplication() + // Check activity pub urls are valid + checkActivityPubUrls() + .catch(err => { + logger.error('Error in ActivityPub URLs checker.', { err }) + process.exit(-1) + }) + // Email initialization Emailer.Instance.init() await Emailer.Instance.checkConnectionOrDie() @@ -199,6 +183,7 @@ async function startApplication () { // Caches initializations VideosPreviewCache.Instance.init(CONFIG.CACHE.PREVIEWS.SIZE) + VideosCaptionCache.Instance.init(CONFIG.CACHE.VIDEO_CAPTIONS.SIZE) // Enable Schedulers BadActorFollowScheduler.Instance.enable()