Created
June 21, 2018 12:04
-
-
Save ChugunovRoman/6051d87faf15c5dd59d93d716e667311 to your computer and use it in GitHub Desktop.
Simple static server with Expressjs
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 path from "path"; | |
import Express from 'express'; | |
const root = process.cwd(); | |
const p = path.resolve(root, 'build'); | |
const app = Express(); | |
app.use(Express.static(p)); | |
app.get('/', (req, res) => { | |
res.sendFile(`${p}/index.html`, { | |
headers: { | |
'Content-Type': 'text/html' | |
} | |
}); | |
}); | |
app.listen(process.env.PORT, (err) => { | |
if (err) throw err; | |
console.log(`Server is running on localhost:${process.env.PORT}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment