From 13a1f490fc9a13b319d1ecf7ed414942f68a312e Mon Sep 17 00:00:00 2001 From: phantomjinx Date: Tue, 17 Apr 2018 11:53:21 +0100 Subject: [PATCH] TEIIDTOOLS-341: Ensure routes in address bar are handled correctly * Ensure that Angular, rather than Express, handle manually entered paths in browser address bar. --- ngapp/server.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ngapp/server.js b/ngapp/server.js index 15ea47ab..d4854d9c 100644 --- a/ngapp/server.js +++ b/ngapp/server.js @@ -6,8 +6,24 @@ app.use(bodyParser.json()); // Create link to Angular build directory var distDir = __dirname + "/dist/"; + +// +// Serves all the dist directory as a web application +// app.use(express.static(distDir)); +// +// Catch-all route that ensures any paths added to the host +// in the address bar, eg. example.com/dataservices, are passed +// on to the angular app to handle. +// +// Ensures that manually entered addresses are handled by +// angular and express remains a simple passthrough. +// +app.get('*', function (req, res) { + res.sendFile(distDir + '/index.html'); +}); + // Initialize the app. var server = app.listen(process.env.PORT || 8080, function () { var port = server.address().port;