Last active
June 10, 2018 13:44
-
-
Save teochengyong/32c41ed9b36d5c8a5cf28e63a82f4fc0 to your computer and use it in GitHub Desktop.
Using express to serve Angular App
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
| const express = require('express'); | |
| const compression = require('compression') | |
| const path = require('path'); | |
| const app = express() | |
| app.use(compression()); | |
| const port = process.env.PORT || 8080; | |
| // static file serve | |
| const dirName = 'dist' | |
| app.use(express.static(path.resolve(`${dirName}`))) | |
| // not found in static files, so default to index.html | |
| app.use((req, res) => res.sendFile(path.resolve(`${dirName}/index.html`))) | |
| app.listen(port, (e, b) => { | |
| console.log(`Server has started in port ${port}`); | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment