Created
August 25, 2017 20:13
-
-
Save Willovent/c7b250153251a16d9130d81c0cace8d8 to your computer and use it in GitHub Desktop.
This file contains 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 { renderModuleFactory } from '@angular/platform-server'; | |
import { enableProdMode } from '@angular/core'; | |
import { AppServerModuleNgFactory } from './aot/src/app/app.server.module.ngfactory'; | |
import * as express from 'express'; | |
import * as fs from 'fs'; | |
enableProdMode(); | |
const app = express(); | |
const ngEngine = (filePath, options, callback) => { | |
const file = fs.readFileSync(filePath).toString(); | |
renderModuleFactory(AppServerModuleNgFactory, { | |
document: file, | |
url: options.req.url | |
}) | |
.then(string => { | |
callback(null, string); | |
}); | |
}; | |
app.engine('html', ngEngine); | |
app.set('view engine', 'html'); | |
app.set('views', '.'); | |
app.use(express.static('.')); | |
app.get('*', (request, response) => { | |
response.render('index', { req: request }); | |
}); | |
app.listen(8000, () => { | |
console.log('listening...'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment