@FlantasticDan I think they are just using a static project with folders and lots of index.htmls, in which case adding a not found page is not possible.
Lol it seems I misread the last part of the question.
Glitch static projects are served using lws but because you don’t have access to the configuration I’d agree that a custom 404 isn’t possible with the Glitch configuration.
Might be a good idea for a feature request if Bee is interested.
Actually, adding a 404 page may be possible, assuming they visit a existent page first. Based on how PWAs can work offline by intercepting fetch, you may be able to intercept a fetch request, check if it’s an actual url either by checking it’s existence from a builtin list OR sending a HEAD request to the server, if the page exists pass it through if not send your custom 404 page.
@javaarchive is talking about Service Workers which are a browser feature that allows an origin to run JavaScript on the client independent of a loaded document. They are very powerful and allow for modern web features like web push, caching, and of course progressive web apps.
Google’s Matt Gaunt explains what they are and how they work much better than I could and his article is a great starting point if you want to learn more:
With service workers you could use their caching / fetch interception capabilities to implement a custom 404 page on the client side. You’d need the service worker to cache all the assets, including the document itself, required for the custom 404 page at install, and the user would only see the custom version if they’d already been to your site (and thus have an active service worker).
I totally agree with you, it would be really cool if this feature existed! As a VueJS dev, it’s really annoying when your Vue app uses History mode and can’t really really redirect to index.html instead of telling me that “I found a glitch”.
people reading this, be aware that this is for changing the 404 behavior when the project container is running, i.e., when you’re editing your project and using project hours.
I think Glitch would consider it more appropriate to boost the project if you want to keep it online, rather than to keep it online with automatic reloads.
So the code snippet will launch a server from the package http-server. That same code snippet will block any extra other code execution before the process finishes. When lws launches the server, it will read the config before listening on port 3000 for requests. That blocking code will stop any further reading of the config until glitch shuts down the container. When Glitch shuts down the container, the code will refresh the project and it loops the code over and over again.