kalamuna / kalastatic

:electric_plug: Facilitate the front-end experience through Styleguides and Prototypes
https://kalamuna.github.io/kalastatic/
41 stars 14 forks source link

404 page #537

Open soniktrooth opened 6 years ago

soniktrooth commented 6 years ago

We should add the ability to gracefully handle 404 pages.

Here is an exampe of how to do it with Browsersync:

'use strict';

const content_404 = fs.readFileSync(path.join(__dirname, '404.html'));

const browserSync = require("browser-sync").create();

browserSync.init({
    files: ["app/css/*.css"],
    server: {
        baseDir: "app"
    }
}, (err, bs) => {
    bs.addMiddleware("*", (req, res) => {
        // Provides the 404 content without redirect.
        res.write(content_404);
        res.end();
    });
});

Stolen gracefully from https://github.com/BrowserSync/browser-sync/issues/1398

jeffschwartz commented 1 year ago

But what about the CLI, how would that work?

It'd be awesome to have a command line option like --pageNotFound "./404.html", which would avoid the need to have to use a script. While the above works for those who are already scripting, many would lose the benefit of the CLI just because they need to handle 404.