Forever Loops To Make A 404 Screen

Recently I asked about 404 screens and I did kind of get an answer but instead of their way of making a 404 I was wondering if it was possible to make a simpler version which is a global js script that checks the domains and if its not listed then send them to a 404 page as this just seemed like the easiest solution in my opinion. And cause I have no idea to configure the version that they sent in as a reply.

yup! according to this

const express = require("express");
const app = express();
const port = 3000;
app.all("/no-no-path", (req, res) => {

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)

How can I use this sir?

um so basically, you can do

app.all("/a-path-you-want-404", (req, res) => {

You’re sending me code that I could use if I knew how to make a infinite loop to check lol

um I’m trying to send you code that is you can use. period. can you tell me what you do not understand?

Basically everything you sent Idk how to use any of this code

You put it in an index.js file in a node repl and push run.

Ok I’m going to explain. in great and excruciating detail:

  1. node has a package called express it’s basically used to create webservers, so basically, if you access a url you can specify programmatically what you would like to do
    – for our purpose’s it’s about the same as a WSGI server (Web Server Gateway Interface) written for python to create webserver
  2. basically, node will use this package to allow you to take in bit requests filled with data ranging from the IP, device, and route the person is accessing
  3. you can then use this to create a programmatically made 404 error screen

See this is a great explanation of the why but I need to know the how to get this to work on my site. Cause you expect me to fully understand what you’re saying. For example how do I get the package mins for my site instead of copy and pasting some randoms 400+ line.

I gave you a simple and easy to understand how, did you not see it?

My repl is html. I cant use that lol.

I’m not sure what you mean.

Then you can’t use 404 pages regardless. HTML/CSS/JS repls can’t do that.

1 Like

If I understand what you meant, then if you have a 404.html file, you can make a js file like this to send you there.

const paths = ["/", "/info", "/random"];

if (!path.includes(window.location.path)) {
    window.location.path = "/path/to/404.html";

You could also make paths into a regex.

There is still one problem though, depending on how your backend is set up, it might just give you an error if you go to the wrong page. To make this work, it needs to always send this file to the client no matter what path you are on. It is possible, but not with a regular html, css, and js repl, you would need a backend.

1 Like

Therin lies the problem. They are using that kind of repl.

Yeah and this is a problem I been running into a lot recently. With basically every replit I been given or shown or code samples :joy:

1 Like

I would recommend using a Node.JS repl, as they aren’t that hard to setup, and you can use 404 pages that way.

1 Like

Generally you would do something a little more like this:

app.use(function(req, res) {
    res.sendFile(__dirname + "/404.html");

This has to be the very last app.<request-method> call though, otherwise other requests would be served the 404 page.


I made a template for you here, it’s just a NodeJS Repl which hosts the files you place inside it and also a custom 404 page. The server file is hidden and you don’t have to configure anything to make it as easy as possible :).

1 Like

get isn’t the only request type, using use safely respond to anything left

1 Like