Hello all,
I am getting a strange routing issue when I try to load an Angular
controlled page one directory higher than the node.js server. It just
gives me a 500 Not found error. I use the http and the fs modules of node.
I use http.createServer and a switch statement. I've tried it with both
empty single quotes for the root path and '/' and both are giving the same
500 - Internal Server error. Actually, it gives an error no matter what
path I use. Whether it is localhost:3000 or localhost:3000/about
The code is brief, so I hope someone can tell me what is wrong.
var http = require('http'),
fs = require('fs');
function serveStaticFile(res, path, contentType, responseCode) {
if(!responseCode) responseCode = 200;
fs.readFile(__dirname + path, function(err, data) {
if(err) {
res.writeHead(500, { 'Content-Type': 'text/html'});
res.end('500 - Internal Server Error');
} else {
res.writeHead(responseCode,
{'Content-Type' : contentType});
res.end(data);
}
});
}
http.createServer(function(req, res) {
// normalize url by removing querystring, optional
// trainling slash, and making lowercase
var path = req.url.toLowerCase();
switch(path) {
case '/':
serveStaticFile(res, '../index.html', 'text/html');
break;
case '/about':
serveStaticFile(res, '../about.html', 'text/html');
break;
default:
serveStaticFile(res, '../404.html', 'text/html', 404);
break;
}
}).listen(3000);
console.log('Server started at localhost:3000; press Ctrl-C to
terminate...');
Thanks in advance,
Bruce
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.