Created
March 2, 2019 14:32
-
-
Save avishwakarma/bcddbb42a030ae1ab5ba827a4640bc85 to your computer and use it in GitHub Desktop.
Angular Universal KoaJS server
This file contains hidden or 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 * 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