[abandoned] How to add a "404 page not found" on my website?

Hello !

So, I created a page specifically for the 404 error, but I can not get Glitch to use it to replace the page with “not found”.

Could you help me ?
Thank you very much.

Are you using something like Express, or did you use the ‘webpage’ option when creating the project and thus have static files?

1 Like

I did not use Express

Hello @Darkyyyyy

I’ll happily help you to add a 404 error page to your server,
just send me a invite in DMs.

Okay ! I send you that

Hello !

I’m sending this message just to say that I’m still looking for help :sweat_smile:

You’ve made a website project, you should use the hello-express template. then use my example.

I do not know how to use “express”, it’s for his that I ask here because I went around the internet …
I’m giving up…

This page in the Express docs explains how to use routing https://expressjs.com/en/guide/routing.html, and how to add a 404 is explained here: https://expressjs.com/en/starter/faq.html

If I’m created a website hosted on Glitch (see example here), is there any workaround to change 404 page or I need to convert my codebase to Express?

Hey @AJHaliliDev2006PH, your project is using a static web page template, which in Glitch uses https://github.com/lwsjs/local-web-server. You could use that package’s interface to write a middleware component to provide your custom 404 page, and it’s possible someone’s already done something in the vein that you could incorporate.

Using Express also seems to require writing some sort of special handling, but it may be better documented.

2 Likes

Thanks a lot, @cori!

So, I need to convert my codebase into fully Express or follow your advice, @cori?

P.S. The quoted post was corrected using Grammarly, so my apologies.

I think a custom 404 would be really useful for almost all of the static sites on Glitch.

I had a go at this, I managed to alter the lws config, and experimentally routed all pages to 404, was funny but not so useful … I couldn’t work out how to get lws to use an additional middleware, if anyone has worked that out it’d be useful.

Yes, at the moment, converting to express is the most practical way.

Following Gareth’s link above, you could do this after the other routes

app.use(function (req, res, next) {
  res.status(404).send("Sorry can't find that!")
})

or to use a page

app.use(function (req, res, next) {
  response.sendFile(__dirname + '/views/404.html');
})

How to convert to express … start a new express project, copy the server.js and package.json to your own project.

1 Like

Hello

I recomend you to see the question https://support.glitch.com/t/a-way-to-make-custom-404-page-for-glitch-website-applications/5260
1 Like

Remix the project on the link bellow:

Hey @TiagoRangel, for the future, please aviod bumping old threads.

3 Likes

Olá, @RiversideRocks, obrigado, mas como assim?

Please don’t respond to old threads (you just did it)

1 Like

hey could you help me too?