I am trying to create a simple single page application using MEAN stack.
So far I worked on a localhost, and everything worked fine.
Sadly after uploading the code to the server I am getting status code 500 (Internal Server Error) whenever my application try to download anything from my partial folder (HTML templates).
It is not CORS problem (same domain) but just to be sure I also installed CORS plugin.
Example route:
$routeProvider.when('/admin/login', {
templateUrl: 'partials/admin/login.html',
controller: 'AdminLoginCtrl'
});
I also have the path setting:
router.get('*', function(request, response) {
response.sendfile('./public/index.html');
});
I've searched through many pages and I am not able to find a solution. Thank you for any help.
Do you know that you are sending the index.html for every request?
Change this:
router.get('*', function(request, response) {
response.sendfile('./public/index.html');
});
To this:
app.use(express.static(path.join(__dirname, 'public')));
Or this:
app.use('/path', express.static(path.join(__dirname, 'public')));
if you went to serve the static files under some path other than /
.
Make sure to add this to the beginning of your file:
var path = require('path');
Also make sure that you actually have the public
directory in the correct place and that it includes the index.html
and other required files.
Of course you may have other problems since you have obviously not included your entire code.
See my example on GitHub if you want to serve static files with Express:
- https://github.com/rsp/node-express-static-example
It is a working example that you can download, put your own static content in the correct directory and customize for your own needs.
More examples to do the same with and without Express:
- https://github.com/rsp/node-static-http-servers
Other related answers:
- How to serve an image using nodejs
- Failed to load resource from same directory when redirecting Javascript
- onload js call not working with node
- Sending whole folder content to client with express
- Node JS not serving the static image