-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
executable file
·42 lines (35 loc) · 1.11 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/node
const http = require('http');
const bodyParser = require("body-parser");
const express = require('express');
const api = require('./api');
const app = express();
const preInitPromises = [
api.milight.bridges.init()
];
// Middlewares et configurations
app.use(bodyParser.json());
app.use(express.static(__dirname + '/public'))
// Création serveur HTTP
const server = http.createServer(app)
// Ecoute serveur HTTP après initialisation de l'API Milight
Promise.all(preInitPromises).then(function () {
server.listen(3000);
console.log("[EXPRESS] HTTP server listening ...");
}).catch(function () {
console.log("[EXPRESS] HTTP server start script failed : init error ...");
});
// REST API
const RESTAPI = require('./rest')(app);
// Static file serving
app.get('*', function (req, res) {
if (process.env.NODE_ENV == 'production') {
res.sendFile('./app-prod.html', { root: __dirname });
} else {
res.sendFile('./app.html', { root: __dirname });
}
});
// Socket.io API
const io = require('socket.io')(server);
const socketAPI = require('./socket')(io);
socketAPI.listen();