Skip to content

Instantly share code, notes, and snippets.

@eelayoubi
Last active December 13, 2020 21:45
Show Gist options
  • Save eelayoubi/0da507405b12ad96c26e313ad5be9a79 to your computer and use it in GitHub Desktop.
Save eelayoubi/0da507405b12ad96c26e313ad5be9a79 to your computer and use it in GitHub Desktop.
Angular Lambda SSR
import 'zone.js/dist/zone-node';
import { join } from 'path';
import * as fs from 'fs';
import { renderModule, AppServerModule } from './src/main.server';
import * as express from 'express';
export const app = express();
const distFolder = join(process.cwd(), 'dist/angular-lambda-ssr/browser');
app.set('view engine', 'html');
app.set('views', distFolder);
// Example Express Rest API endpoints
// app.get('/api/**', (req, res) => { });
// Serve static files from /browser
app.get('*.*', express.static(distFolder, {
maxAge: '1y'
}));
// All regular routes use the Universal engine
app.get('*', (req, res) => {
fs.readFile(join(__dirname, '../browser/index.html'), function (err, html) {
if (err) {
throw err;
}
renderModule(AppServerModule, {
document: html.toString(),
url: req.url
}).then((html) => {
res.send(html);
});
});
});
export * from './src/main.server';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment