lwsjs / local-web-server

A lean, modular web server for rapid full-stack development.
MIT License
1.21k stars 85 forks source link

Configuring virtual host #33

Closed web-padawan closed 8 years ago

web-padawan commented 8 years ago

Is there a way to implement virtual host config? For now, I simply add my host alias into /etc/hosts and it proxifies me to 127.0.0.1 But in my opinion it would be nice to be able to configure it.

I looked for koa adapter and found two versions: koa-vhost and vhost-koa. Both are developed for older koa versions. I tried first of those, but it seems that I'm doing something wrong. The way I include it is like this:

  if (options.host) {
    const vhost = require('koa-vhost')
    debug('host', options.host)
    app.use(vhost({
      host: options.host,
      app: app
    }))
  }
75lb commented 8 years ago

no, we don't currently support virtual hosts.. is that feature necessary for a local development server? Currently, ws does not pay any attention to the hostname of the client request..

To begin with, please implement this feature in a separate module extending local-web-server.. if you have some success with the feature, and think all ws users would benefit from it, we could later absorb it into local-web-server.. so, your extension would look something like this:

const app = localWebServer()
app.use(myVirtualHostMiddleware)

const server = http.createServer(serverOptions, app.callback())
server.listen(8000)
web-padawan commented 8 years ago

Thanks for explanation! I'll try it out.