1

I have a working chat application ( tutorial here : https://www.youtube.com/watch?v=QISU14OrRbI ) hooked to mysql instead of mongodb.

All of my code in a paste, minus the css : http://pastebin.com/j5FLZyFP

I have always been able to link to a css file via the link element in the DOM head. I am wondering why this approach doesn't work in my example and if it has anything to do with which ports i am using. The server that serves the index.html page is running on port 8080, while my sockets server is running on port 9000. Should I be using the same port for both of them? If so, how do I do that?

Below are screenshots of my browser @ 127.0.0.1:8080

I need 10 reputation to post more than 2 links, slap my wrist I suppose - https[colon][slash][slash]imgur[dot]com[slash]a[slash]22Vv5

I get served the page, but i am forced to press ESC to stop the main.css from getting transferred. Then the remaining requests come through. don't be concerned about inject.js, it represents the Wappalyzer extension and I have tried the example with Wappalyzer disabled.

Adding my CSS to a style tag works and isn't too much trouble to implement in my case, but it would be nice to solve this problem. Thanks.

3
  • Similar question and solution is here : stackoverflow.com/questions/12134554/… Commented Apr 12, 2015 at 5:48
  • So I have to use the 'url' and 'fs' packages to load the (all) external resources? That seems do-able. Thanks a lot! I'll try it out later with fresh eyes and mark as solved if it works. Commented Apr 12, 2015 at 5:55
  • Its better to use some node framework like express. it will take care of lot of things and you will not have to write everything from scratch. Commented Apr 12, 2015 at 6:02

1 Answer 1

0

Kamran Adil in the comments has answered this well. See linked question: Node.js - external JS and CSS files (just using node.js not express)

this worked just fine adding a new condition to test the request

    var param = 'main'; /* Stylesheet file name */

if(req.url.indexOf('.css') != -1) {
    fs.readFile('./styles/'+ param +'.css', function (err, data) {
	if (err) { console.log(err); }
	res.writeHead(200, {'Content-Type': 'text/css'});
	res.write(data);
	res.end();
    });
}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.