angularjs - Why am I still being served my entire application when I'm using res.send("HELLO WORLD") in ExpressJS -
we using mean stack project, , have client side routing via angularjs if that's important. however, i'm wondering why client receives files @ since sending "hello world". help!
edit: realized problem has app.use(express.static(__dirname + '/public')); // set static files location /public/img /img users removing makes impossible serve css/js/other resources user.
var express = require('express'); var app = express(); var port = process.env.port || 8080; // set our port // routes ================================================== require('./app/routes')(app); // pass our application our routes // start app =============================================== app.listen(port); app.use(methodoverride('x-http-method-override')); // override x-http-method-override header in request. simulate delete/put app.use(express.static(__dirname + '/public')); // set static files location /public/img /img users exports = module.exports = app; //file: ./app/routes module.exports = function(app) { app.get('*', function(req, res) { res.send("hello world"); }); }
as pointed out, express.static serving angular app each request.
you can 2 things:
add different static (so express serves static files multiple directories) paths so:
app.use(express.static(__dirname + '/public/img')); app.use(express.static(__dirname + '/public/css'));move routes above static files / or serve angular app manually so:
// test route before serving static content app.get('/', function(req, res){ //send app on req }) app.use(express.static(__dirname + '/public'));this mean express evaluate request , try find matching route before looking static content.
Comments
Post a Comment