Can't load


I'm creating an app that has separate server and client code (two different git repositories).

The HTML is there just as a UI, but it still needs to load /socket/ in order to communicate with the server.

This is my HTML:

        <script src="/socket/"></script>
        <script src="js/myStuff.js"></script>


When queried with an address that starts with /c, the server will automatically replace the prefix with the client code directory. So, the website is loaded like this: localhost:8080/c/index.html, and the request for js/myStuff.js is actually /c/js/myStuff.js.

This is how it's all implemented:

var http = require("http");
var io = require("");
var fs = require("fs");
var iniparser = require("iniparser");

var config = iniparser.parseSync('./config.ini');

clientPath = config.server.clientPath; //   ../../Bla

var handler = function(req, res)
    if (req.url[1] == "c")
        req.url = req.url.slice(2, req.url.length); //Cut off the "/c"
        url = __dirname + "/" + clientPath + req.url;
        url = req.url; //Nothing.

    fs.readFile (url, function(err, data)
        if (err)
            return res.end("File not found.");


var server = http.createServer(handler);
var socket = io.listen(server);

Both myStuff.js and index.html load correctly, but there is a problem with loading /socket/ That is very, very strange, because I don't even touch the address.

This error is given by Google Chrome:

GET http://localhost:8080/socket/ 404 (Not Found)

Why is this happening and how can I fix it?

Problem courtesy of: jcora


It doesn't look as if you are changing it anywhere so the default location for the JavaScript is

<script src="/"></script>

not socket/

Solution courtesy of: Daff


There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.