Skip to content

Instantly share code, notes, and snippets.

@Willovent
Created August 25, 2017 20:13
Show Gist options
  • Save Willovent/c7b250153251a16d9130d81c0cace8d8 to your computer and use it in GitHub Desktop.
Save Willovent/c7b250153251a16d9130d81c0cace8d8 to your computer and use it in GitHub Desktop.
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