mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
ported to static site, removed _ext folder, split hbs files into partials
This commit is contained in:
47
server.js
47
server.js
@@ -6,30 +6,10 @@ 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 {
|
||||
console.log("Server: Successfully served index.html");
|
||||
|
||||
/*setTimeout(()=>{
|
||||
console.log('closing server');
|
||||
res.app.server.close();
|
||||
process.exit();
|
||||
},1000*10); */
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Better to show landing page rather than 404 on editor page reload
|
||||
app.get('/pixel-editor/app', (req, res) => {
|
||||
res.redirect('/');
|
||||
})
|
||||
|
||||
//ROUTE - other files
|
||||
app.use(express.static(path.join(__dirname, BUILDDIR)));
|
||||
app.use('/pixel-editor', express.static(path.join(__dirname, BUILDDIR)));
|
||||
|
||||
|
||||
// "reload" module allows us to trigger webpage reload automatically on file changes, but inside pixel editor it also
|
||||
// makes browser steal focus from any other window in order to ask user about unsaved changes. It might be quite
|
||||
@@ -46,3 +26,26 @@ if (process.env.RELOAD === "yes") {
|
||||
console.log(`Web server listening on port ${PORT}`);
|
||||
})
|
||||
}
|
||||
|
||||
// Better to show landing page rather than 404 on editor page reload
|
||||
app.get('/', (req, res) => {
|
||||
res.redirect('/pixel-editor');
|
||||
})
|
||||
|
||||
|
||||
//ROUTE - match / or any route with just numbers letters and dashes, and return index.htm (all other routes should have been handled already)
|
||||
app.get(['/pixel-editor', /^\/pixel-editor\/[\/a-z0-9-]+$/gi ], (req, res) => {
|
||||
res.sendFile(path.join(__dirname, BUILDDIR, 'index.htm'), {}, function (err) {
|
||||
if (err) {
|
||||
console.log('error sending file', err);
|
||||
} else {
|
||||
console.log("Server: Successfully served index.html", req.originalUrl);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Better to show landing page rather than 404 on editor page reload
|
||||
app.get('/pixel-editor/app', (req, res) => {
|
||||
res.redirect('/');
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user