2023-10-21 16:16:11 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies.
|
|
|
|
*/
|
2023-10-31 16:00:25 +00:00
|
|
|
var log = require("loguix")
|
|
|
|
var {LogType} = require("loguix")
|
|
|
|
var { __glob } = require("./global-variables")
|
|
|
|
log.setup(__glob.LOGS)
|
2023-11-02 10:09:47 +00:00
|
|
|
|
2023-11-02 17:16:15 +00:00
|
|
|
const wlog = new LogType("Serveur")
|
|
|
|
|
|
|
|
if(process.env.DEV ) {
|
|
|
|
|
|
|
|
wlog.log("MODE DEVELOPEMENT ACTIF")
|
|
|
|
}
|
2023-11-02 10:09:47 +00:00
|
|
|
|
2023-10-31 16:00:25 +00:00
|
|
|
wlog.step.init("start_server", "Démarrage du serveur Express JS")
|
2023-10-21 16:16:11 +00:00
|
|
|
|
|
|
|
var app = require('../main');
|
|
|
|
var http = require('http');
|
2023-11-02 10:09:47 +00:00
|
|
|
var config = require("./config")
|
2023-11-28 20:05:44 +00:00
|
|
|
var serverIO = require("./servers")
|
2023-10-31 16:00:25 +00:00
|
|
|
|
2023-10-21 16:16:11 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
2023-11-02 17:16:15 +00:00
|
|
|
serverIO.serverIO(server)
|
2023-10-21 16:16:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Listen on provided port, on all network interfaces.
|
|
|
|
*/
|
|
|
|
|
2023-10-31 16:00:25 +00:00
|
|
|
|
2023-10-21 16:16:11 +00:00
|
|
|
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':
|
2023-10-31 16:00:25 +00:00
|
|
|
wlog.step.error("start_server", bind + ' requires elevated privileges');
|
2023-10-21 16:16:11 +00:00
|
|
|
process.exit(1);
|
|
|
|
break;
|
|
|
|
case 'EADDRINUSE':
|
2023-10-31 16:00:25 +00:00
|
|
|
wlog.step.error("start_server" , bind + ' is already in use');
|
2023-10-21 16:16:11 +00:00
|
|
|
process.exit(1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event listener for HTTP server "listening" event.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function onListening() {
|
2023-11-02 10:09:47 +00:00
|
|
|
wlog.log("Serveur entrain d'écouter sur le port : " + server.address().port)
|
2023-10-21 16:16:11 +00:00
|
|
|
var addr = server.address();
|
|
|
|
var bind = typeof addr === 'string'
|
|
|
|
? 'pipe ' + addr
|
|
|
|
: 'port ' + addr.port;
|
2023-10-31 16:00:25 +00:00
|
|
|
wlog.step.end("start_server")
|
2023-11-02 10:09:47 +00:00
|
|
|
}
|