Express won't get a subdomain file

So is the app.post meant to post the /home file?

This doesn’t work but am I still on the right track?

1 Like

I think you should render /public/trolled/home/index.html, instead of simply redirecting to /home/

Like this?

1 Like

No, rendering [dirname] + “/public/trolled/home/home.html”, not /home/ :sweat_smile:
Edit: home.html not index.html

Did this but still nothing

1 Like

Oops not index.html but home.html

Still doesn’t work but also will it automatically redirect to /home?

Think of it this way.

app.get is a computer getting data from a server
app.post is a computer pushing data to a server

in your code above, you are sending a file named home. You need to send /public/trolled/home/home.html, or if that does not work /trolled/home/home.html

This should be inside a app.get

2 Likes

:+1:

I tried both of those but still says cannot POST /home
image

you have too many return statements by the way

1 Like

Nothing but do you think the req.session.user could be making it screw up

what kind of nothing are you getting? http 502?

Cannot POST /home but if i put /home at the end of the url it shows error ENOENT no such file or directory, stat ‘/app/home’

okay I see you’ve removed the redirect… and this new code looks wrong in many ways. other than the aforementioned multiple returns,

  • doing app.get in a handler doesn’t redirect or serve that other file. it adds a new handler while the app is in the middle of responding. definitely not what you want to do
  • plus that new handler is going to respond to poeple who go to whatever.glitch.me/public/trolled/home/home.html rather than whatever.glitch.me/home.

sorry to say, but you’re getting way off track trying to follow many different people’s vague suggestions

2 Likes

Here is what you need to serve a web page:

//app.get
app.get("/", (req, res) => {
  res.sendFile(__dirname + "/NavToContainingDirectory/changethistoyourhomepage.html");
});

change the “/” in the app.get to where you want the page to show up, and change the text after __dirname to your HTML file your want to serve.

1 Like

Yup on the first handler you should only have “/home/”, and the too many returns in the code can probably mess up with it.

Ok so, there is also a res.send that sends the login page with the form data and when you submit it it sends this


So should I instead send the POST data to another page that checks the pass email and other stuff which then redirects to the /home with the user data?
(I found this out because no matter what I put in the if (isValid) string it would always say cannot post /home).

sounds like your design for this has changed since we last talked. previously you were going to have the browser POST to /login and then redirect to /home. but now you’re having it post directly to /home? why the change?