laktek / punch

A fun and easy way to build modern websites
http://laktek.github.com/punch
MIT License
1.17k stars 107 forks source link

Can I forward certain paths to a different server with a reverse proxy? #86

Open blakeblackshear opened 11 years ago

blakeblackshear commented 11 years ago

I want to add the ability to forward requests to a path like /api1/* to a server.

I could add this by putting in some middleware before the call to setup page_server in this line: https://github.com/laktek/punch/blob/master/lib/server.js#L34

However, I was thinking that there may be a better way to resolve urls than how it is done inside the page_server on this line: https://github.com/laktek/punch/blob/master/lib/page_server.js#L251

What about using route style matching from other serverside frameworks to be able to resolve the path with any arbitrary plugin from the config? I am thinking something like this in the config:

"paths": {
  "/api1/.*": {
    "name": "punch-http-proxy",
    "options": {
      "port": 80,
      "host": "remote.server.com"
    }
  },
  "**/*.bundle.js": {
    "name": "requirejs-bundler",
    "options": {
      "buildFile": "app-build-file"
    }
  },
  "**/*.js": "coffee-script",
  "**/*.css": "stylus"
}

Thoughts? Am I trying to fit a square peg in a round hole?

laktek commented 11 years ago

This seems a good idea. I'm actually evaluating on a better routing mechanism where multiple content handlers can be plugged-in.

But for now I guess you can write your own custom server, which uses page_server as a middleware.

blakeblackshear commented 11 years ago

Sounds good. I would love to help as I am using punch for my entire development workflow on angular apps. Having a better understanding of where punch is heading would help me with future pull requests. On Jun 7, 2013 2:04 AM, "Lakshan Perera" notifications@github.com wrote:

This seems a good idea. I'm actually evaluating on a better routing mechanism where multiple content handlers can be plugged-in.

But for now I guess you can write your own custom server, which uses page_server as a middleware.

— Reply to this email directly or view it on GitHubhttps://github.com/laktek/punch/issues/86#issuecomment-19092122 .