2020-04-04 10:36:08 +03:00
|
|
|
const path = require('path');
|
|
|
|
const express = require('express');
|
|
|
|
|
|
|
|
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){
|
2021-01-13 22:21:43 +03:00
|
|
|
console.log('error sending file', err);
|
2020-04-04 10:36:08 +03:00
|
|
|
} else {
|
2021-01-13 22:21:43 +03:00
|
|
|
console.log("Server: Successfully served index.html");
|
2020-04-04 10:36:08 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
//ROUTE - other files
|
|
|
|
app.use(express.static(path.join(__dirname, BUILDDIR)));
|
|
|
|
|
|
|
|
//start server
|
|
|
|
var server = app.listen(PORT, () => {
|
|
|
|
console.log(`\nTemp server started at http://localhost:${PORT}!`);
|
|
|
|
//console.log('press ctrl+c to stop ');
|
|
|
|
|
2020-04-04 18:43:31 +03:00
|
|
|
var opn = require('open');
|
2020-04-04 10:36:08 +03:00
|
|
|
|
|
|
|
// opens the url in the default browser
|
|
|
|
opn(`http://localhost:${PORT}`);
|
|
|
|
});
|
|
|
|
|