neutral/bin/www

108 lines
2.0 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env node
/**
* Module dependencies.
*/
var log = require("loguix")
var {LogType} = require("loguix")
var { __glob } = require("./global-variables")
log.setup(__glob.LOGS)
const wlog = new LogType("Serveur")
if(process.env.DEV ) {
wlog.log("MODE DEVELOPEMENT ACTIF")
}
wlog.step.init("start_server", "Démarrage du serveur Express JS")
var app = require('../main');
var http = require('http');
var config = require("./config")
2023-11-28 20:05:44 +00:00
var serverIO = require("./servers")
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '3001');
app.set('port', port);
/**
* Create HTTP server.
*/
var server = http.createServer(app);
serverIO.serverIO(server)
/**
* Listen on provided port, on all network interfaces.
*/
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);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}
/**
* Event listener for HTTP server "error" event.
*/
function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}
var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
wlog.step.error("start_server", bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
wlog.step.error("start_server" , bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}
/**
* Event listener for HTTP server "listening" event.
*/
function onListening() {
wlog.log("Serveur entrain d'écouter sur le port : " + server.address().port)
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
wlog.step.end("start_server")
}