Skip to content

Instantly share code, notes, and snippets.

@warrendodsworth
Last active November 25, 2019 02:43
Show Gist options
  • Save warrendodsworth/d8d30dbecbcf9589fa97c2cda660aa25 to your computer and use it in GitHub Desktop.
Save warrendodsworth/d8d30dbecbcf9589fa97c2cda660aa25 to your computer and use it in GitHub Desktop.
<script>
// to dynamically set base url by reading the virtual servers path from the url
// doesn't work perfectly, causes double load as the first set of script calls fire to the base / url without the vd, then the second set go to the vd url (runtime.js etc)
let p = location.pathname.split('/').filter(x => x);
let baseHref = '/';
if (!location.origin.includes('localhost:4200')) {
baseHref += p[0] + '/' + p[1] + '/' + p[2] + '/';
}
console.log('baseHref', baseHref);
window['base-href'] = baseHref;
document.write(`<base href="${window['base-href']}" />`);
</script>
const express = require('express');
const path = require('path');
const server = express();
const port = process.env.PORT || 3000;
const rootPath = path.join(__dirname, 'dist');
// set vd path
var virtualDirPath = '/vd/myapp/';
// dist
server.use(virtualDirPath, express.static(path.join(__dirname, 'dist')));
// node_modules
server.use(virtualDirPath + 'node_modules', express.static(path.join(__dirname, 'node_modules')));
// Setup a route at the index of our app
server.get(virtualDirPath, (req, res) => {
return res.sendFile(path.resolve(__dirname, 'dist', 'index.html'));
});
server.listen(port, () => {
console.log(`Listening on ${port}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment