mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Enforce style, split build into build and server, parametrize build.js and server.js
This commit is contained in:
committed by
Théo (Lattay) Cavignac
parent
a10453c7cb
commit
4123c069e2
37
server.js
Normal file
37
server.js
Normal file
@@ -0,0 +1,37 @@
|
||||
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){
|
||||
console.log('error sending file',err);
|
||||
} else {
|
||||
setTimeout(()=>{
|
||||
console.log('closing server');
|
||||
server.close();
|
||||
process.exit();
|
||||
},1000*10);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//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 ');
|
||||
|
||||
var opn = require('opn');
|
||||
|
||||
// opens the url in the default browser
|
||||
opn(`http://localhost:${PORT}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user