In related issue https://github.com/BrowserSync/browser-sync/issues/862 was suggested that snippet as an example how redirecting to 404 can be achieved.
However, I found out that example isn't accurate. It _redirects_ to 404 page, thus changing final url from /myWrongUrl to /404.html, while actually it have to _substitute_ response and show content of 404.html, without affecting final url, by making 404.html content available under /myWrongUrl with status code 404.
Is it possible to achieve? I tried to figure it out through docs, but, unfortunately, some parts are almost undocumented, so it's uneasy to understand which methods should be used for this.
Would be greatful for any help.
Have you tried providing the 404 content like this:
'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();
});
});
Most helpful comment
Have you tried providing the 404 content like this: