Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serving Angular app using Express

I'm building an Angular app served using Express on Node.

What I'd like to do is when the user visits the site, append their locale to the url (domain.com/en-gb).

Then regardless of what locale they have specified serve up the same index.html.

app.use('/', function(req, res) {
   res.sendFile(__dirname + '/public/index.html');
});

The problem I'm having is working out how to serve up the same file regardless of request, but allowing assets such as images to not be rerouted to index.html as well?

Thanks, Harry

like image 488
harrynorthover Avatar asked Apr 11 '16 13:04

harrynorthover


1 Answers

If you add a use statement like the following one, you specify the location for your images:

var staticPathImages = __dirname + '/assets/images';
app.use(express.static(staticPathImages));

express will serve those static assets directly, without re-routing to index.html...

like image 120
MarcoS Avatar answered Sep 22 '22 16:09

MarcoS