import 'zone.js/dist/zone-node' ; import 'reflect-metadata' ; import { enableProdMode } from '@angular/core' ; import { ngExpressEngine } from '@nguniversal/express-engine' ; import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader' ; import * as express from 'express' ; import { join } from 'path' ; enableProdMode ( ) ; const app = express ( ) ; const PORT = process . env . PORT || 4000 ; const DIST_FOLDER = join ( process . cwd ( ) , 'dist' ) ; const { AppServerModuleNgFactory , LAZY_MODULE_MAP } = require ( './server/main' ) ; app . engine ( 'html' , ngExpressEngine ( { bootstrap : AppServerModuleNgFactory , providers : [ provideModuleMap ( LAZY_MODULE_MAP ) ] } ) ) ; app . set ( 'view engine' , 'html' ) ; app . set ( 'views' , join ( DIST_FOLDER , 'browser' ) ) ; app . get ( '*.*' , express . static ( join ( DIST_FOLDER , 'browser' ) , { maxAge : '1y' } ) ) ; app . get ( '*' , ( req , res ) => { const supportedLocales = [ 'en' , 'es' ] ; const defaultLocale = 'en' ; const matches = req . url . match ( /^\/([a-z]{2}(?:-[A-Z]{2})?)\// ) ; const locale = ( matches && supportedLocales . indexOf ( matches [ 1 ] ) !== - 1 ) ? matches [ 1 ] : defaultLocale ; res . render ( `${ locale }/index` , { req } ) ; } ) ; app . listen ( PORT , ( ) => { console . log ( `Node Express server listening on http://localhost:${ PORT }` ) ; } ) ;