Skip to content

Instantly share code, notes, and snippets.

@lamogura
Created January 10, 2017 06:58
Show Gist options
  • Select an option

  • Save lamogura/9ad1f9ab7ab7e3e72bfb55764ae654fa to your computer and use it in GitHub Desktop.

Select an option

Save lamogura/9ad1f9ab7ab7e3e72bfb55764ae654fa to your computer and use it in GitHub Desktop.
brunch proxied dev server
// 1. npm i -D express http-proxy
// 2. add to config: "server: { path: 'dev_server' }"
const express = require('express')
const sysPath = require('path')
const http = require('http')
const httpProxy = require('http-proxy')
const apiProxy = httpProxy.createServer({
target: 'http://localhost:3000'
})
// https://github.com/brunch/brunch-guide/blob/master/content/en/chapter10-web-server.md
exports.startServer = function (port, path, done) {
const app = express()
app.use(express['static'](path))
app.all('/api/*', (req, res) => {
return apiProxy.web(req, res)
})
app.all('/*', (req, res) => {
return res.sendFile(sysPath.resolve(sysPath.join(path, 'index.html')))
})
server = http.createServer(app)
server.listen(parseInt(port, 10), done)
return server
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment