Skip to content

Instantly share code, notes, and snippets.

@beeman
Created May 20, 2018 07:11
Show Gist options
  • Save beeman/ee6475be0fe0b3636291015fbdba99eb to your computer and use it in GitHub Desktop.
Save beeman/ee6475be0fe0b3636291015fbdba99eb to your computer and use it in GitHub Desktop.
Express server for Angular Universal with an Angular CLI v6 app
import * as express from 'express';
import { join } from 'path';
import { ngExpressEngine } from '@nguniversal/express-engine';
import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader';
const PORT = process.env.PORT || 8080;
const staticRoot = join(process.cwd(), 'dist', 'store');
const {AppServerModuleNgFactory, LAZY_MODULE_MAP} = require('./dist/store-server/main');
const app = express();
app.engine('html', ngExpressEngine({
bootstrap: AppServerModuleNgFactory,
providers: [
provideModuleMap(LAZY_MODULE_MAP)
]
}));
app.set('view engine', 'html');
app.set('views', staticRoot);
app.get('*.*', express.static(staticRoot));
app.get('*', (req, res) => res.render('index', {req}));
app.listen(PORT, () => console.log(`Server listening on http://localhost:${PORT}`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment