HTML doesn't load, even though it looks like it should

I tried adding a website to my node project, but the website will not load and just says “OK”, but will not load the website

Hey there and welcome to the glitch support forum!

When asking for help on one of your projects, it is always useful to post your project’s name so we can have a look under the hood to see what is actually going on, and in this case going wrong.

As I am seeing it, you probably need to change a response.sendStatus(200); with a response.sendFile(__dirname+"/filename.html");, if you built this on an express app. Give it a try, make sure to use a reference to your HTML file. If it doesn’t work, post your project name here and I’ll have a look.

Good luck with your website! Happy glitching!

This has linked the html properly, but now the css does not get linked. The project name is athenadiscordbot but it is set to private (i put this under glitch, not discord bot as the bot is not what im having issues with). if you can acess the file, the result.sendFile is in the athenabot.js and the webpage is index.html and styles.css

Oh interesting – if the result.sendFile is in the athenabot, I think this might be an issue which I also had at one point – namely that I wasn’t explicitly sending back index.html in server.js when a user hit the / route. (Basically what @TsjipTsjip was saying, minus the response.sendStatus(200) part, which I haven’t had to explicitly do.)

(i.e., something like this: -->

app.get('/', function(request, response) {
  response.render('pages/index');
});

or like this (the one above is using a rendering engine and the one below is not)

app.get("/", function(request, response) {
  response.sendFile(__dirname + "/views/index.html");
});

That’s my best advice without being able to see the code – good luck!

Without seeing your project I might not be too helpful, but here are a few other things you can try:

  • That you have a link to the CSS from your HTML page, that it’s properly formatted, and the URL matches the place on the server where your CSS file exists, and
  • That you are serving the directory where the CSS file is. If you are using express, that might mean adding a line like app.use(express.static("public/")); to serve the directory called public.

Thanks all, the combination of all 3 responses managed to get the CSS working too :smiley:

@househaunt Yeah, I believe the response.sendStatus(200); is a default setting from the express webserver template. Might be completely off there though, I’ll leave it in the middle.


@Timemaster111 Glad we could help you out! Good luck with your project, if you have any other questions, don’t hesitate to ask. The only dumb questions are questions which aren’t asked!