Skip to content

Instantly share code, notes, and snippets.

@ramsaylanier
Created January 14, 2019 17:38
Show Gist options
  • Save ramsaylanier/c323d267786ed7eff1b6c8197fe1c1e4 to your computer and use it in GitHub Desktop.
Save ramsaylanier/c323d267786ed7eff1b6c8197fe1c1e4 to your computer and use it in GitHub Desktop.
Module Docs server
const express = require("express")
const webpack = require("webpack")
const config = require("../webpack.config")
const devMiddleware = require("webpack-dev-middleware")
const compiler = webpack(config)
const bodyParser = require("body-parser")
// controller to handle API requests
const FileController = require("./controllers")
// Probably should make this configurable
const PORT = 4444
module.exports = (modulePath, config) => {
const app = express()
app.use(bodyParser.json())
// start webpack dev server
app.use(
devMiddleware(compiler, {
open: true,
stats: "errors-only"
})
)
// handles getting package names from node_modules
app.post("/modules", FileController.getFiles(modulePath, config))
// handles getting the package info and README from a package
app.post("/module/:name", FileController.getPackage(modulePath))
app.get("*", function response(req, res) {
res.sendFile("./client/template.html", { root: __dirname })
})
app.listen(PORT, () => {
console.log(`Module Docs is running at http://localhost:${PORT}`)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment