From d397c3fa54087f605ff4f6feae26838548e01c6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hubert=20Figui=C3=A8re?= Date: Mon, 18 Sep 2023 11:31:23 -0400 Subject: [PATCH] nodejs: use let and const instead of var Close #16 --- webapp/nodejs/app.js | 18 ++++++++------- webapp/nodejs/bin/www | 34 ++++++++++++++-------------- webapp/nodejs/public/index.html | 16 +++++++------- webapp/nodejs/routes/index.js | 39 +++++++++++++++++---------------- webapp/nodejs/routes/wopi.js | 8 ++++--- 5 files changed, 61 insertions(+), 54 deletions(-) diff --git a/webapp/nodejs/app.js b/webapp/nodejs/app.js index 99893e6..9dc6536 100644 --- a/webapp/nodejs/app.js +++ b/webapp/nodejs/app.js @@ -1,16 +1,18 @@ -var express = require('express'); -var path = require('path'); -var logger = require('morgan'); -var bodyParser = require('body-parser'); +'use strict'; -var indexRouter = require('./routes/index'); -var wopiRouter = require('./routes/wopi'); +let express = require('express'); +let path = require('path'); +let logger = require('morgan'); +let bodyParser = require('body-parser'); + +let indexRouter = require('./routes/index'); +let wopiRouter = require('./routes/wopi'); // maximum request body size handled by the bodyParser package // increase it if you need to handle larger files -var maxDocumentSize = '100kb'; +const maxDocumentSize = '100kb'; -var app = express(); +let app = express(); app.use(logger('dev')); app.use(express.json()); diff --git a/webapp/nodejs/bin/www b/webapp/nodejs/bin/www index 88b7e3b..624da94 100755 --- a/webapp/nodejs/bin/www +++ b/webapp/nodejs/bin/www @@ -1,22 +1,24 @@ #!/usr/bin/env node -var app = require('../app'); -var debug = require('debug')('untitled:server'); -var http = require('http'); -var https = require('https'); -var fs = require('fs'); -var env = require('process').env; +'use strict'; -var port = normalizePort(process.env.PORT || '3000'); +let app = require('../app'); +let debug = require('debug')('untitled:server'); +let http = require('http'); +let https = require('https'); +let fs = require('fs'); +let env = require('process').env; + +let port = normalizePort(process.env.PORT || '3000'); app.set('port', port); -var server; -var proto; +let server; +let proto; -var hasCerts = env["SSL_KEY_FILE"] && env["SSL_CRT_FILE"]; +let hasCerts = env["SSL_KEY_FILE"] && env["SSL_CRT_FILE"]; if (hasCerts) { - var privateKey = fs.readFileSync(env["SSL_KEY_FILE"]); - var certificate = fs.readFileSync(env["SSL_CRT_FILE"]); + let privateKey = fs.readFileSync(env["SSL_KEY_FILE"]); + let certificate = fs.readFileSync(env["SSL_CRT_FILE"]); server = https.createServer({ key: privateKey, @@ -32,7 +34,7 @@ server.on('error', onError); server.on('listening', onListening); function normalizePort(val) { - var port = parseInt(val, 10); + let port = parseInt(val, 10); if (isNaN(port)) { // named pipe @@ -52,7 +54,7 @@ function onError(error) { throw error; } - var bind = typeof port === 'string' + let bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port; @@ -75,8 +77,8 @@ function onError(error) { } function onListening() { - var addr = server.address(); - var bind = typeof addr === 'string' + let addr = server.address(); + let bind = typeof addr === 'string' ? 'pipe ' + addr : `${proto}://localhost:${addr.port}/`; console.log(`Listening on ${bind}`); diff --git a/webapp/nodejs/public/index.html b/webapp/nodejs/public/index.html index fec9dcb..f45f592 100644 --- a/webapp/nodejs/public/index.html +++ b/webapp/nodejs/public/index.html @@ -27,12 +27,12 @@