Created
March 5, 2019 19:55
-
-
Save medeirosjoaquim/c3e8376a62b2273db164ed92d636a1f1 to your computer and use it in GitHub Desktop.
simple ExpressJS spa
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 bodyParser = require('body-parser') | |
| const path = require('path') | |
| const app = express() | |
| // assets. Static JS, CSS, fonts | |
| app.use('/public', express.static(path.join(__dirname, '../public'))) | |
| app.use(bodyParser.urlencoded({ extended: false })) | |
| app.use(bodyParser.json()) | |
| // SPA default configuration | |
| // it is important to declare this after the assets rule | |
| app.get('*', (req, res, next) => { | |
| res.sendFile('path to your html file') | |
| }) | |
| // start server | |
| const server = app.listen(process.env.PORT || 3000, () => { | |
| console.log(`server running on port ${server.address().port}`) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment