Skip to content

Instantly share code, notes, and snippets.

@avishwakarma
Created March 2, 2019 14:32
Show Gist options
  • Select an option

  • Save avishwakarma/bcddbb42a030ae1ab5ba827a4640bc85 to your computer and use it in GitHub Desktop.

Select an option

Save avishwakarma/bcddbb42a030ae1ab5ba827a4640bc85 to your computer and use it in GitHub Desktop.
Angular Universal KoaJS server
import * as Koa from 'koa';
import * as serve from 'koa-static';
import { readFileSync } from 'fs';
import { join } from 'path';
// the middileware universal.ts
// https://gist.github.com/ashokvishwakarma/7c97578108e49fb38d06777e8319bb24
import universal from './universal';
// construct the dist/browser folder path here
// where your have all the static files
// for your web application
const BORWSER_DIR = join(process.cwd(), 'dist', 'browser');
const app: Koa = new Koa();
app
.use(serve(BORWSER_DIR, {
// important so that koa-static does not serve index.html
// as directory index
index: false,
gzip: true
}))
.use(universal);
app.listen(4000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment