Created
September 29, 2016 11:55
-
-
Save giacomorebonato/49919551d02fc82f6ef0e2ca0095aa6f to your computer and use it in GitHub Desktop.
simple ExpressJS spa
This file contains 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
Then the start script in
package.json
should be something likenode ./server/server.js