refactor: www -> es6 syntax

This commit is contained in:
Khaled Garbaya
2017-09-20 12:06:27 +02:00
committed by Benedikt Rötsch
parent dc3e8628f3
commit 3f6efdf750
2 changed files with 30 additions and 31 deletions

59
bin/www
View File

@@ -4,76 +4,75 @@
* Module dependencies.
*/
var app = require('../app');
var debug = require('debug')('example-contentful-university-js:server');
var http = require('http');
const app = require('../app')
const http = require('http')
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
const port = normalizePort(process.env.PORT || '3000')
app.set('port', port)
/**
* Create HTTP server.
*/
var server = http.createServer(app);
const server = http.createServer(app)
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
server.listen(port)
server.on('error', onError)
server.on('listening', onListening)
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val) {
var port = parseInt(val, 10);
function normalizePort (val) {
const port = parseInt(val, 10)
if (isNaN(port)) {
// named pipe
return val;
return val
}
if (port >= 0) {
// port number
return port;
return port
}
return false;
return false
}
/**
* Event listener for HTTP server "error" event.
*/
function onError(error) {
function onError (error) {
if (error.syscall !== 'listen') {
throw error;
throw error
}
var bind = typeof port === 'string'
const bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
: 'Port ' + port
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
console.error(bind + ' requires elevated privileges')
process.exit(1)
break
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
console.error(bind + ' is already in use')
process.exit(1)
break
default:
throw error;
throw error
}
}
@@ -81,10 +80,10 @@ function onError(error) {
* Event listener for HTTP server "listening" event.
*/
function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
function onListening () {
const addr = server.address()
const bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
console.log('Listening on ' + bind);
: 'port ' + addr.port
console.log('Listening on ' + bind)
}

View File

@@ -6,7 +6,7 @@
"start:watch": "nodemon ./bin/www --ignore public/",
"start": "node ./bin/www",
"lint": "eslint ./app.js routes",
"format": "eslint --fix . --ignore public node_modules"
"format": "eslint --fix . bin --ignore public node_modules"
},
"dependencies": {
"body-parser": "~1.15.2",