neutral/bin/www
Raphix b19243a8af
All checks were successful
Neutral/pipeline/head This commit looks good
Version 0.4.0 - Ajout des metrics
2023-11-28 21:05:44 +01:00

108 lines
2.0 KiB
JavaScript

#!/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")
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")
}