/service/X route behaves strangely

I was playing around with a node js server the other day, and I saw that when I tried to reach the /service/X route it did something weird.

Repl: https://replit.com/@SharkCoding/server
Code:

const express = require("express");

const app = express();

app.get("*", (req, res) => {
    console.log(req.path);
    res.send("Path: " + req.path);
});

app.listen(3000, () => {
    console.log("server started");
});

All I did was go to the /service/randomtext route and it should have logged /service/randomtext but instead logged /sw.js. I am a bit confused as to what is happening here. Does anyone have an explanation for this?

I played around with it and everything works. But I don’t see the folder you are talking about

oh, oops, I just realized ive been editing the same repl i used to post this :l

1 Like

You should be able to see the issue now. You can also go to: https://server.sharkcoding.repl.co/service/randomtext to see that it doesn’t do what I expected.

When I click on that link (on Chrome, Windows 11 and on Chrome on an Android device) I see Path: /service/randomtext

2 Likes

hmm, this is what I get:

I found the problem.

1 Like

I’m assuming you’ve edited the code, because now I get Cannot GET /service/randomtext.

Yes, I’ve changed it. I was using this to run an Ultraviolet server, and it uses a service worker that does stuff when you call a /service/x path, which is why this happened. Everything is fixed now though, and I got it to do what I originally wanted.

1 Like