diff options
-rw-r--r-- | server.js | 56 |
1 files changed, 28 insertions, 28 deletions
@@ -1,41 +1,41 @@ | |||
1 | 'use strict' | 1 | 'use strict' |
2 | 2 | ||
3 | // ----------- Node modules ----------- | 3 | // ----------- Node modules ----------- |
4 | var bodyParser = require('body-parser') | 4 | const bodyParser = require('body-parser') |
5 | var express = require('express') | 5 | const express = require('express') |
6 | var expressValidator = require('express-validator') | 6 | const expressValidator = require('express-validator') |
7 | var http = require('http') | 7 | const http = require('http') |
8 | var morgan = require('morgan') | 8 | const morgan = require('morgan') |
9 | var path = require('path') | 9 | const path = require('path') |
10 | var TrackerServer = require('bittorrent-tracker').Server | 10 | const TrackerServer = require('bittorrent-tracker').Server |
11 | var WebSocketServer = require('ws').Server | 11 | const WebSocketServer = require('ws').Server |
12 | 12 | ||
13 | // Create our main app | 13 | // Create our main app |
14 | var app = express() | 14 | const app = express() |
15 | 15 | ||
16 | // ----------- Checker ----------- | 16 | // ----------- Checker ----------- |
17 | var checker = require('./server/initializers/checker') | 17 | const checker = require('./server/initializers/checker') |
18 | 18 | ||
19 | var miss = checker.checkConfig() | 19 | const miss = checker.checkConfig() |
20 | if (miss.length !== 0) { | 20 | if (miss.length !== 0) { |
21 | throw new Error('Miss some configurations keys : ' + miss) | 21 | throw new Error('Miss some configurations keys : ' + miss) |
22 | } | 22 | } |
23 | 23 | ||
24 | // ----------- PeerTube modules ----------- | 24 | // ----------- PeerTube modules ----------- |
25 | var config = require('config') | 25 | const config = require('config') |
26 | var constants = require('./server/initializers/constants') | 26 | const constants = require('./server/initializers/constants') |
27 | var customValidators = require('./server/helpers/customValidators') | 27 | const customValidators = require('./server/helpers/customValidators') |
28 | var database = require('./server/initializers/database') | 28 | const database = require('./server/initializers/database') |
29 | var installer = require('./server/initializers/installer') | 29 | const installer = require('./server/initializers/installer') |
30 | var logger = require('./server/helpers/logger') | 30 | const logger = require('./server/helpers/logger') |
31 | var poolRequests = require('./server/lib/poolRequests') | 31 | const poolRequests = require('./server/lib/poolRequests') |
32 | var routes = require('./server/controllers') | 32 | const routes = require('./server/controllers') |
33 | var utils = require('./server/helpers/utils') | 33 | const utils = require('./server/helpers/utils') |
34 | var videos = require('./server/lib/videos') | 34 | const videos = require('./server/lib/videos') |
35 | var webtorrent = require('./server/lib/webtorrent') | 35 | const webtorrent = require('./server/lib/webtorrent') |
36 | 36 | ||
37 | // Get configurations | 37 | // Get configurations |
38 | var port = config.get('listen.port') | 38 | const port = config.get('listen.port') |
39 | 39 | ||
40 | // ----------- Database ----------- | 40 | // ----------- Database ----------- |
41 | database.connect() | 41 | database.connect() |
@@ -65,7 +65,7 @@ app.use(require('connect-livereload')({ | |||
65 | require('segfault-handler').registerHandler() | 65 | require('segfault-handler').registerHandler() |
66 | 66 | ||
67 | // API routes | 67 | // API routes |
68 | var api_route = '/api/' + constants.API_VERSION | 68 | const api_route = '/api/' + constants.API_VERSION |
69 | app.use(api_route, routes.api) | 69 | app.use(api_route, routes.api) |
70 | 70 | ||
71 | // Static files | 71 | // Static files |
@@ -82,7 +82,7 @@ app.use('/*', function (req, res, next) { | |||
82 | 82 | ||
83 | // ----------- Tracker ----------- | 83 | // ----------- Tracker ----------- |
84 | 84 | ||
85 | var trackerServer = new TrackerServer({ | 85 | const trackerServer = new TrackerServer({ |
86 | http: false, | 86 | http: false, |
87 | udp: false, | 87 | udp: false, |
88 | ws: false, | 88 | ws: false, |
@@ -97,8 +97,8 @@ trackerServer.on('warning', function (err) { | |||
97 | logger.error(err) | 97 | logger.error(err) |
98 | }) | 98 | }) |
99 | 99 | ||
100 | var server = http.createServer(app) | 100 | const server = http.createServer(app) |
101 | var wss = new WebSocketServer({server: server, path: '/tracker/socket'}) | 101 | const wss = new WebSocketServer({server: server, path: '/tracker/socket'}) |
102 | wss.on('connection', function (ws) { | 102 | wss.on('connection', function (ws) { |
103 | trackerServer.onWebSocketConnection(ws) | 103 | trackerServer.onWebSocketConnection(ws) |
104 | }) | 104 | }) |
@@ -107,7 +107,7 @@ wss.on('connection', function (ws) { | |||
107 | 107 | ||
108 | // Catch 404 and forward to error handler | 108 | // Catch 404 and forward to error handler |
109 | app.use(function (req, res, next) { | 109 | app.use(function (req, res, next) { |
110 | var err = new Error('Not Found') | 110 | const err = new Error('Not Found') |
111 | err.status = 404 | 111 | err.status = 404 |
112 | next(err) | 112 | next(err) |
113 | }) | 113 | }) |