Use const in main server file

This commit is contained in:
Chocobozzz 2016-03-21 21:13:10 +01:00
parent 37dc07b292
commit 13ce1d01c9

View File

@ -1,41 +1,41 @@
'use strict' 'use strict'
// ----------- Node modules ----------- // ----------- Node modules -----------
var bodyParser = require('body-parser') const bodyParser = require('body-parser')
var express = require('express') const express = require('express')
var expressValidator = require('express-validator') const expressValidator = require('express-validator')
var http = require('http') const http = require('http')
var morgan = require('morgan') const morgan = require('morgan')
var path = require('path') const path = require('path')
var TrackerServer = require('bittorrent-tracker').Server const TrackerServer = require('bittorrent-tracker').Server
var WebSocketServer = require('ws').Server const WebSocketServer = require('ws').Server
// Create our main app // Create our main app
var app = express() const app = express()
// ----------- Checker ----------- // ----------- Checker -----------
var checker = require('./server/initializers/checker') const checker = require('./server/initializers/checker')
var miss = checker.checkConfig() const miss = checker.checkConfig()
if (miss.length !== 0) { if (miss.length !== 0) {
throw new Error('Miss some configurations keys : ' + miss) throw new Error('Miss some configurations keys : ' + miss)
} }
// ----------- PeerTube modules ----------- // ----------- PeerTube modules -----------
var config = require('config') const config = require('config')
var constants = require('./server/initializers/constants') const constants = require('./server/initializers/constants')
var customValidators = require('./server/helpers/customValidators') const customValidators = require('./server/helpers/customValidators')
var database = require('./server/initializers/database') const database = require('./server/initializers/database')
var installer = require('./server/initializers/installer') const installer = require('./server/initializers/installer')
var logger = require('./server/helpers/logger') const logger = require('./server/helpers/logger')
var poolRequests = require('./server/lib/poolRequests') const poolRequests = require('./server/lib/poolRequests')
var routes = require('./server/controllers') const routes = require('./server/controllers')
var utils = require('./server/helpers/utils') const utils = require('./server/helpers/utils')
var videos = require('./server/lib/videos') const videos = require('./server/lib/videos')
var webtorrent = require('./server/lib/webtorrent') const webtorrent = require('./server/lib/webtorrent')
// Get configurations // Get configurations
var port = config.get('listen.port') const port = config.get('listen.port')
// ----------- Database ----------- // ----------- Database -----------
database.connect() database.connect()
@ -65,7 +65,7 @@ app.use(require('connect-livereload')({
require('segfault-handler').registerHandler() require('segfault-handler').registerHandler()
// API routes // API routes
var api_route = '/api/' + constants.API_VERSION const api_route = '/api/' + constants.API_VERSION
app.use(api_route, routes.api) app.use(api_route, routes.api)
// Static files // Static files
@ -82,7 +82,7 @@ app.use('/*', function (req, res, next) {
// ----------- Tracker ----------- // ----------- Tracker -----------
var trackerServer = new TrackerServer({ const trackerServer = new TrackerServer({
http: false, http: false,
udp: false, udp: false,
ws: false, ws: false,
@ -97,8 +97,8 @@ trackerServer.on('warning', function (err) {
logger.error(err) logger.error(err)
}) })
var server = http.createServer(app) const server = http.createServer(app)
var wss = new WebSocketServer({server: server, path: '/tracker/socket'}) const wss = new WebSocketServer({server: server, path: '/tracker/socket'})
wss.on('connection', function (ws) { wss.on('connection', function (ws) {
trackerServer.onWebSocketConnection(ws) trackerServer.onWebSocketConnection(ws)
}) })
@ -107,7 +107,7 @@ wss.on('connection', function (ws) {
// Catch 404 and forward to error handler // Catch 404 and forward to error handler
app.use(function (req, res, next) { app.use(function (req, res, next) {
var err = new Error('Not Found') const err = new Error('Not Found')
err.status = 404 err.status = 404
next(err) next(err)
}) })