Search code examples
node.jsexpressfreeboard

Appending to url path in express


I am building freeboard using freeboard.io. I am running it on a node server using express. I use

router.get('/', function(req, res, next) {

        res.sendFile(path.join(__dirname + '/index.html'));
    });

to send the freeboard html file when the base route is hit. However, in order for freeboard to load my saved dashboard I need to append #source=dashboard.json to the url. So the final url would look like

http://localhost:8080/#source=dashboard.json

is there some way I can do this using express? Pretty much when I hit localhost:8080/ I want to append to the url path #source=dashboard.json and respond with the index.html file. Thanks!


Solution

  • The fragment section of the URL is never sent to the server by the browser. See here for more info. Therefore for the server the fragment will always be missing even if the user has entered it on the URL field. In this case redirecting the browser back with the same URL inclusing the fragment may be the wrong thing.