-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
19 lines (18 loc) · 909 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const express = require('express');
const app = express();
// Run the app by serving the static files
// in the dist directory
app.use(express.static(__dirname + '/dist'));
// Start the app by listening on the default
// Heroku port
app.listen(process.env.PORT || 8080);
// For routing, Angular apps employ PathLocationStrategy by default, meaning that there won't be any hashes in the URL.
// This is generally cleaner and more desirable, but it comes at the cost of sub-routes not being accessible when
// someone navigates directly to them. What's required to make PathLocationStrategy work properly is some configuration
// on the server, and fortunately, it's fairly easy with express.
const path = require('path');
// For all GET requests, send back index.html
// so that PathLocationStrategy can be used
app.get('/*', function(req, res) {
res.sendFile(path.join(__dirname + '/dist/index.html'));
});