On my project i’m trying to make it redirect to the /home page but when I put /home at the end of the url it shows “Cannot GET /home/” app.get("/", function (request, response) { response.sendFile(__dirname + "/views"); }); app.get("/", function (request, response) { response.sendFile(__dirname + "/trolled"); }); app.get("/", function (request, response) { response.sendFile(__dirname + "/home"); });
Everything else but /home works but the files are arranged like so
If you want my project name is “samhamsemporium.”
I previously had the /home file by itself and not in the /trolled file and it did the same thing but, When i put app.get("/home", . . .) it shows cannot POST /home instead of cannot GET /home/.
If I put https://samhamsemporium.glitch.me/home/ manually in the browser without logging in it says Error: ENOENT: no such file or directory, stat '/app/home'
For the static middleware do you mean: app.use(express.static("public"));
and is this a solution for the sendfile thing? app.get("/", function (request, response) { response.sendFile(__dirname + "/trollled/home"); });
(you can go to my project to see the code btw Glitch :・゚✧)
And for the “cannot POST” It’s handling a form submission from a .post, then checks a database if it’s valid and does a redirect to /home with a session for the user if (isValid) { return res.redirect("/home"); return (req.session.user = "user"); } });
I know the code works because if the password isin’t correct it correctly displays “Incorrect password” and the redirect works too because I tried it on /trolled and it redirected to /trolled but its just the /home file not working.
yup, that’s what I mean by the static middleware. it’s a different way from writing your own app.get( ... response.sendFile(...) ... ) for each URL you want to have. but it makes the URLs have things like .html at the end (there may be some way to configure it not to, dunno).
for the “cannot POST” It’s handling a form submission from a .post, then checks a database if it’s valid and does a redirect to /home with a session for the user
if you’ve written up this piece of code to do that database check, then it sounds like it’s not registered on the app object right.
Ah so what should I do to make the page actually display html content.
I know it’s not the redirect but i think it’s something to do with the middleware.
My redirect is going to /home and when I put / in the browser it redirects to the front page of my project (Which I want it to do) and when I go to /home manually in my browser it says Error: ENOENT: no such file or directory, stat '/app/home BUT when I use the login button and put in the form data the error is Cannot POST /home which leads me to believe that it’s an error with it grabbing the data from the database but I don’t know because i’m new to this. Also I know the login code is correct because when I enter an incorrect username and pass it says “incorrect password” but if i enter it correctly it says the cannot post thing.