saurabhnanda/odd-jobs

Support for custom URL roots

Opened this issue · 3 comments

I'm looking into using odd-jobs to replace a home-spun job queue implementation. The web UI is really useful, but I would like to put it behind a subpath on an auth-protected domain which I use for all my dev UIs, so that I can still access it remotely.

Currently, I using a reverse-proxy to do that - so the web UI is served on a URL like

https://my.dev.domain/jobs/

and that routes to

http://127.0.0.1:<odd-jobs-port>

However, the UI doesn't currently really support this. All of the static assets and links are broken, since they expect to be served from the URL root /, rather than the /jobs/ path. It would be great if odd-jobs would support custom URL roots, so I could use it in the above way.

@ivanbakel I believe the code already supports this. Please take a look at the following function -

mkEnv :: (MonadIO m) => Config -> (Text -> Text) -> m Env
mkEnv cfg@Config{..} linksFn = do
allJobTypes <- fetchAllJobTypes cfg
allJobRunners <- fetchAllJobRunners cfg
envJobTypesRef <- newIORef allJobTypes
envJobRunnersRef <- newIORef allJobRunners
let envRoutes = routes linksFn
The second argument is a function that allows you to transform the links generated by the web UI to whatever you want. This "hook" was added specifically for your use-case.

Are you starting the web UI via the default command-line? We can probably add another flag --web-ui-root-path to make this easier without having to write custom code.

Good to know, thanks! I am using the default command-line settings to start the web UI, so a flag would be really useful. I'll make a PR to support doing that.

@ivanbakel before you work on the PR, please take a look at #76 -- this might make your PR easier.