ajxchapman / ReServ

A set of simple servers (currently HTTP/HTTPS and DNS) which allow configurable and scriptable responses to network requests.
59 stars 6 forks source link

How to remap urls to scripts #10

Closed ajxchapman closed 4 years ago

ajxchapman commented 4 years ago

The following routes can all map to the same script:

[
  {
        "protocol" : "http",
        "route" : "^/(.*)",
        "path" : "./wwwroot/$1"
    },
    {
        "protocol" : "http",
        "route" : "^/scripts/(.*)",
        "path" : "./wwwroot/scripts/$1"
    },
    {
        "protocol" : "http",
        "route" : "^/runme/(.*)",
        "path" : "./wwwroot/scripts/runme.py"
    },
    {
        "protocol" : "http",
        "route" : "^/test([^/]*)",
        "path" : "./wwwroot/scripts/runme.py"
    }
]

How should the URL be remapped in each instance?

ajxchapman commented 4 years ago

I think this is best addressed by adding a remap_url, HTTP route configuration option with a regex to grok the remapped URL from the original url

ajxchapman commented 4 years ago

Currently using the following

    "route" : "^/httpbin/.*",
    "url" : {
      "base" : "/httpbin",
      "remap" : "/httpbin/(.*)"
    }

This feels like a lot of unnecessary re-definition, is there a better way?

ajxchapman commented 4 years ago

Settling on something more like the below when a remap is required:

    "route" : "^/httpbin/.*",
    "path" : {
      "path" : "./scripts/httpbin.py",
      "base" : "/httpbin"
    },

But still allowing the usual path when a remap is not needed:

    "route" : "^/httpbin/.*",
    "path" : "./files/wwwroot/blah"
ajxchapman commented 4 years ago

Closed out in 0afea2f46e66501a40cc31e1ad6f1a408479c22b