Serving an Angular Application with Express

I am creating an Angular application that runs using Express on Node.

What I would like to do is when a user visits the site, adds his locale to the URL (domain.com/en-gb).

Then no matter what language they specify, it serves the same index.html.

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

The problem I ran into is how to process the same file regardless of the request, but do I allow objects like images not to be redirected to index.html?

Thanks Harry

+4
source share
2 answers

use, , :

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

express , index.html...

+3

MarcoS , :

app.use(express.static(path.join(__dirname, 'public'))); //this line enables the static serving in the public directory

public :

public 
|_css
|_js
|_images
  |_logo.png

, :

http://localhost:3000/images/logo.png

html:

<img id="logo" src="/images/logo.png"/>
+2

All Articles