diff --git a/build.js b/build.js index 5b4b4d0..3a2b332 100644 --- a/build.js +++ b/build.js @@ -17,6 +17,8 @@ console.log('Building Pixel Editor'); function copy_images(){ // Icons gulp.src('./images/*.png').pipe(gulp.dest(BUILDDIR)); + //favicon + gulp.src('./images/*.ico').pipe(gulp.dest(BUILDDIR)); // Splash images gulp.src('./images/Splash images/*.png').pipe(gulp.dest(BUILDDIR)); // Logs images diff --git a/css/_canvas.scss b/css/_canvas.scss index 46f6b74..1b8d602 100644 --- a/css/_canvas.scss +++ b/css/_canvas.scss @@ -1,7 +1,7 @@ .drawingCanvas { - cursor: url('/pixel-editor/pencil-tool-cursor.png'); + cursor: url('pencil-tool-cursor.png'); border: solid 1px #fff; image-rendering: optimizeSpeed; diff --git a/css/_colors-menu.scss b/css/_colors-menu.scss index ec70b43..a19277d 100644 --- a/css/_colors-menu.scss +++ b/css/_colors-menu.scss @@ -112,7 +112,7 @@ button { border: none; width: 100%; - cursor: url('/pixel-editor/eyedropper.png'), auto; + cursor: url('eyedropper.png'), auto; } //white outline &.selected button::before { content: ""; diff --git a/css/_popup-container.scss b/css/_popup-container.scss index b81cf3e..5e05ad3 100644 --- a/css/_popup-container.scss +++ b/css/_popup-container.scss @@ -116,7 +116,7 @@ } .dropdown-button { - background: $basehover url('/pixel-editor/dropdown-arrow.png') right center no-repeat; + background: $basehover url('dropdown-arrow.png') right center no-repeat; border: none; border-radius: 4px; color: $basehovertext; @@ -126,7 +126,7 @@ width: 200px; text-align: left; &:hover { - background: $baseselected url('/pixel-editor/dropdown-arrow-hover.png') right center no-repeat; + background: $baseselected url('dropdown-arrow-hover.png') right center no-repeat; color: $baseselectedtext; } &.selected { diff --git a/images/favicon.ico b/images/favicon.ico new file mode 100644 index 0000000..0c0b66b Binary files /dev/null and b/images/favicon.ico differ diff --git a/js/tools/PanTool.js b/js/tools/PanTool.js index af54a5e..628de71 100644 --- a/js/tools/PanTool.js +++ b/js/tools/PanTool.js @@ -10,7 +10,7 @@ class PanTool extends Tool { super.onStart(mousePos); if (target.className != 'drawingCanvas') return; - currFile.canvasView.style.cursor = "url(\'/pixel-editor/pan-held.png\'), auto"; + currFile.canvasView.style.cursor = "url(\'pan-held.png\'), auto"; } onDrag(mousePos, target) { @@ -31,12 +31,12 @@ class PanTool extends Tool { if (target.className != 'drawingCanvas') return; - currFile.canvasView.style.cursor = "url(\'/pixel-editor/pan.png\'), auto"; + currFile.canvasView.style.cursor = "url(\'pan.png\'), auto"; } onSelect() { super.onSelect(); - currFile.canvasView.style.cursor = "url(\'/pixel-editor/pan.png\'), auto"; + currFile.canvasView.style.cursor = "url(\'pan.png\'), auto"; } onDeselect() { diff --git a/server.js b/server.js index 3bb5c2e..3fcb6b0 100644 --- a/server.js +++ b/server.js @@ -5,12 +5,46 @@ const app = express(); const BUILDDIR = process.argv[2] || './build'; const PORT = process.argv[3] || 3000; +const FULLBUILDPATH = path.join(__dirname, BUILDDIR) +//LOGGING +app.use((req, res, next)=> { + //console.log('REQUEST', req.method+' '+req.originalUrl, res.statusCode); + next(); +}); + + +//apply to every request +app.use((req, res, next) => { + //disable caching + res.set("Cache-Control", "no-store"); + + //enabled/disable reload module + if (process.env.RELOAD === "yes") res.locals.reload = true; + + return next(); +}); //ROUTE - other files -app.use('/pixel-editor', express.static(path.join(__dirname, BUILDDIR))); +app.use('/', express.static(FULLBUILDPATH, { + //custom function required for logging static files + setHeaders: (res, filePath, fileStats) => { + console.info('GET', '/'+path.relative(FULLBUILDPATH, filePath), res.statusCode); + } +})); + +//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('/', (req, res, next) => { + console.log('root') + res.sendFile(path.join(__dirname, BUILDDIR, 'index.htm'), {}, function (err) { + console.log('sent file'); + return next(); + }); +}); + +//HOT RELOADING // "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 // intrusive so we decided to give option to choose preferred workflow. @@ -19,6 +53,7 @@ if (process.env.RELOAD === "yes") { //start server app.server = app.listen(PORT, () => { console.log(`Web server listening on port ${PORT} (with reload module)`); + }) }); } else { @@ -27,25 +62,13 @@ if (process.env.RELOAD === "yes") { }) } -// 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); - } - }); +app.use(function(req, res, next) { + res.status(404); + res.type('txt').send('The requested resource does not exist. Did you spell it right? Did you remember to build the app? It\'s probably your fault somehow.'); + return next(); }); -// Better to show landing page rather than 404 on editor page reload -app.get('/pixel-editor/app', (req, res) => { - res.redirect('/'); -}) - +//LOGGING +app.use((req, res, next)=> { + console.log(req.method+' '+req.originalUrl, res.statusCode); +}); diff --git a/views/index.hbs b/views/index.hbs index afc1e25..af4a57e 100644 --- a/views/index.hbs +++ b/views/index.hbs @@ -6,7 +6,7 @@