Created
          May 20, 2018 07:11 
        
      - 
      
- 
        Save beeman/ee6475be0fe0b3636291015fbdba99eb to your computer and use it in GitHub Desktop. 
    Express server for Angular Universal with an Angular CLI v6 app
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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