-
-
Save xgqfrms/ccdbfcc78d859d7d91d9ab6647f0e4e4 to your computer and use it in GitHub Desktop.
express static server
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
/** | |
* express static server for react build/dist test! | |
*/ | |
// simple express server for HTML pages! | |
// ES6 style | |
const express = require('express'); | |
const fs = require('fs'); | |
const hostname = '127.0.0.1'; | |
const port = 3000; | |
const app = express(); | |
let cache = [];// Array is OK! | |
cache[0] = fs.readFileSync( __dirname + '/index.html'); | |
cache[1] = fs.readFileSync( __dirname + '/views/testview.html'); | |
app.get('/', (req, res) => { | |
res.setHeader('Content-Type', 'text/html'); | |
res.send( cache[0] ); | |
}); | |
app.get('/test', (req, res) => { | |
res.setHeader('Content-Type', 'text/html'); | |
res.send( cache[1] ); | |
}); | |
app.listen(port, () => { | |
console.log(` | |
Server is running at http://${hostname}:${port}/ | |
Server hostname ${hostname} is listening on port ${port}! | |
`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment