Created
February 23, 2018 07:35
-
-
Save supnate/1aa961324444b3becbac8abba6d89f19 to your computer and use it in GitHub Desktop.
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 path = require('path'); | |
const http = require('http'); | |
const express = require('express'); | |
const rekitStudioMiddleWare = require('rekit-studio/middleware'); | |
const fallback = require('express-history-api-fallback'); | |
const pkgJson = require('../package.json'); | |
function startStudioServer() { | |
console.log('Starting Rekit Studio...'); | |
const app = express(); | |
const server = http.createServer(app); | |
const root = path.join(__dirname, '../node_modules/rekit-studio/dist'); | |
app.use(rekitStudioMiddleWare()(server, app)); | |
app.use(express.static(root)); | |
app.use(fallback('index.html', { root })); | |
// Other files should not happen, respond 404 | |
app.get('*', (req, res) => { | |
console.log('Warning: unknown req: ', req.path); | |
res.sendStatus(404); | |
}); | |
const port = pkgJson.rekit.studioPort; | |
server.listen(port, (err) => { | |
if (err) { | |
console.error(err); | |
} | |
console.log(`Studio server is listening at http://localhost:${port}/`); | |
}); | |
} | |
startStudioServer(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment