2020-04-04 10:36:08 +03:00
|
|
|
const path = require('path');
|
|
|
|
const express = require('express');
|
2021-04-25 23:03:55 +03:00
|
|
|
const reload = require('reload');
|
2020-04-04 10:36:08 +03:00
|
|
|
const app = express();
|
|
|
|
|
|
|
|
const BUILDDIR = process.argv[2] || './build';
|
|
|
|
const PORT = process.argv[3] || 3000;
|
|
|
|
|
|
|
|
//ROUTE - index.htm
|
|
|
|
app.get('/', (req, res) => {
|
|
|
|
res.sendFile(path.join(__dirname, BUILDDIR, 'index.htm'), {}, function (err) {
|
|
|
|
if(err){
|
|
|
|
console.log('error sending file',err);
|
|
|
|
} else {
|
|
|
|
setTimeout(()=>{
|
|
|
|
console.log('closing server');
|
2021-04-25 23:03:55 +03:00
|
|
|
res.app.server.close();
|
2020-04-04 10:36:08 +03:00
|
|
|
process.exit();
|
|
|
|
},1000*10);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
//ROUTE - other files
|
|
|
|
app.use(express.static(path.join(__dirname, BUILDDIR)));
|
|
|
|
|
2021-04-25 23:03:55 +03:00
|
|
|
reload(app).then(() => {
|
|
|
|
//start server
|
|
|
|
app.server = app.listen(PORT, function () {
|
|
|
|
console.log('Web server listening on port ' + PORT)
|
|
|
|
})
|
2020-04-04 10:36:08 +03:00
|
|
|
});
|