From: Benjamin Auder Date: Tue, 18 Feb 2020 17:19:27 +0000 (+0100) Subject: Remove 'var' keyword from server code X-Git-Url: https://git.auder.net/variants/Chakart/css/assets/doc/html/%7B%7B%20pkg.url%20%7D%7D?a=commitdiff_plain;h=c5c47010b5b50edbdd6bfc40a61ce716c6114e5a;p=vchess.git Remove 'var' keyword from server code --- diff --git a/server/app.js b/server/app.js index 1fc03c59..4f9d167d 100644 --- a/server/app.js +++ b/server/app.js @@ -1,12 +1,12 @@ -var createError = require('http-errors'); -var express = require('express'); -var path = require('path'); -var cookieParser = require('cookie-parser'); -var logger = require('morgan'); -var favicon = require('serve-favicon'); -var params = require('./config/parameters'); +const createError = require('http-errors'); +const express = require('express'); +const path = require('path'); +const cookieParser = require('cookie-parser'); +const logger = require('morgan'); +const favicon = require('serve-favicon'); +const params = require('./config/parameters'); -var app = express(); +let app = express(); app.use(favicon(path.join(__dirname, "static", "favicon.ico"))); diff --git a/server/bin/www b/server/bin/www index 9fd23a44..f11102eb 100755 --- a/server/bin/www +++ b/server/bin/www @@ -4,30 +4,30 @@ * Module dependencies. */ -var app = require('../app'); -var debug = require('debug')('vc:server'); -var http = require('http'); +let app = require('../app'); +const debug = require('debug')('vc:server'); +const http = require('http'); /** * Get port from environment and store in Express. */ -var port = normalizePort(process.env.PORT || '3000'); +const port = normalizePort(process.env.PORT || '3000'); app.set('port', port); /** * Create HTTP server. */ -var server = http.createServer(app); +let server = http.createServer(app); /* * CRON tasks */ -var cron = require('node-cron'); -var UserModel = require("../models/User"); -var GameModel = require("../models/Game"); +let cron = require('node-cron'); +const UserModel = require("../models/User"); +const GameModel = require("../models/Game"); cron.schedule('0 0 0 * * *', function() { // Remove unlogged users and unstarted games every 24h UserModel.cleanUsersDb(); @@ -55,16 +55,16 @@ require('../sockets')(wss); */ function normalizePort(val) { - var port = parseInt(val, 10); + const parsedPort = parseInt(val, 10); - if (isNaN(port)) { + if (isNaN(parsedPort)) { // named pipe return val; } - if (port >= 0) { + if (parsedPort >= 0) { // port number - return port; + return parsedPort; } return false; @@ -79,7 +79,7 @@ function onError(error) { throw error; } - var bind = typeof port === 'string' + const bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port; @@ -103,8 +103,8 @@ function onError(error) { */ function onListening() { - var addr = server.address(); - var bind = typeof addr === 'string' + const addr = server.address(); + const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port; debug('Listening on ' + bind); diff --git a/server/gulpfile.js b/server/gulpfile.js index 99c58ab3..9b24ae8b 100644 --- a/server/gulpfile.js +++ b/server/gulpfile.js @@ -1,7 +1,7 @@ -var gulp = require('gulp'); -var nodemon = require('gulp-nodemon'); //reload server on changes +const gulp = require('gulp'); +const nodemon = require('gulp-nodemon'); //reload server on changes -var nodemonOptions = { +const nodemonOptions = { script: 'bin/www', ext: 'js', env: { 'NODE_ENV': 'development' }, diff --git a/server/models/Challenge.js b/server/models/Challenge.js index 4aae427a..0a375c81 100644 --- a/server/models/Challenge.js +++ b/server/models/Challenge.js @@ -1,4 +1,4 @@ -var db = require("../utils/database"); +const db = require("../utils/database"); const UserModel = require("./User"); /* diff --git a/server/models/Game.js b/server/models/Game.js index b4f128b1..fb249a7c 100644 --- a/server/models/Game.js +++ b/server/models/Game.js @@ -1,4 +1,4 @@ -var db = require("../utils/database"); +const db = require("../utils/database"); const UserModel = require("./User"); /* diff --git a/server/models/News.js b/server/models/News.js index ebe65d04..3f98fd67 100644 --- a/server/models/News.js +++ b/server/models/News.js @@ -1,4 +1,4 @@ -var db = require("../utils/database"); +const db = require("../utils/database"); /* * Structure: diff --git a/server/models/Problem.js b/server/models/Problem.js index 0e900256..8460fec2 100644 --- a/server/models/Problem.js +++ b/server/models/Problem.js @@ -1,4 +1,4 @@ -var db = require("../utils/database"); +const db = require("../utils/database"); /* * Structure: diff --git a/server/models/User.js b/server/models/User.js index d0b105dc..6c0b1539 100644 --- a/server/models/User.js +++ b/server/models/User.js @@ -1,7 +1,7 @@ -var db = require("../utils/database"); -var genToken = require("../utils/tokenGenerator"); -var params = require("../config/parameters"); -var sendEmail = require('../utils/mailer'); +const db = require("../utils/database"); +const genToken = require("../utils/tokenGenerator"); +const params = require("../config/parameters"); +const sendEmail = require('../utils/mailer'); /* * Structure: diff --git a/server/models/Variant.js b/server/models/Variant.js index dccc89b5..d9911071 100644 --- a/server/models/Variant.js +++ b/server/models/Variant.js @@ -1,4 +1,4 @@ -var db = require("../utils/database"); +const db = require("../utils/database"); /* * Structure: diff --git a/server/routes/messages.js b/server/routes/messages.js index d96cbfa2..3f13db4d 100644 --- a/server/routes/messages.js +++ b/server/routes/messages.js @@ -11,7 +11,7 @@ router.post("/messages", (req,res,next) => { const from = req.body["email"]; // Replace potential newline characters in subject const subject = req.body["subject"].replace(/\r?\n|\r/g, " "); - const body = req.body["content"]; //TODO: sanitize? Why? How? + const body = req.body["content"]; mailer(from, params.mail.contact, subject, body, err => { if (!!err)