Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multifile middleware #713

Open
benjih opened this issue Mar 19, 2018 · 3 comments
Open

Support multifile middleware #713

benjih opened this issue Mar 19, 2018 · 3 comments

Comments

@benjih
Copy link
Contributor

benjih commented Mar 19, 2018

Currently, when setting middleware, Hoverfly expects one file to be set as your script. This means any middleware that is split over multiple files is currently incompatible with Hoverfly.

An example of this came up in #557 with a user trying to import another file in Javascript, although this issue is not specfic to JavaScript.

Right now, the script Hoverfly takes in is very basic, hoverctl will read the script and send its contents over HTTP, allowing Hoverfly to persist it. In the past Hoverfly worked on hard path to the script. For a while now though, Hoverfly has written the script to the tmp dir. During this setting process, the script loses the filename. Making things a slightly more complicated.

Workarounds

A workaround to this issue is to convert your multifile middleware into a HTTP server, run that in parallel to Hoverfly and configure Hoverfly with remote middleware, pointing to your localhost middleware HTTP server. The complexity of this workaround is dependant on your language choice. Languages such as Python, Go NodeJS are the easiest to convert into HTTP middleware servers.

@tommysitu tommysitu added this to the v1.1.0 milestone Nov 23, 2018
@tommysitu tommysitu removed this from the v1.1 milestone Jun 4, 2019
@Polyhedron-ZXero
Copy link

Hi, any updates on this? Is there any plan to add this support?

@ns3777k
Copy link
Contributor

ns3777k commented Oct 30, 2021

@tommysitu would this be an option to create an additional flag to hoverctl like --directory that requires a path to a directory with middleware files. inside that directory a file like hoverfly_middleware.json must exist with following contents (example for nodejs):

{
  "entrypoint": "main.js"
}

hoverfly_middleware.json can be extended in future.

hoverctl would zip this directory and send it over to hoverfly. hoverfly would unzip it to a temp directory and set its middleware binary to the one passed with --binary flag and and script to the entrypoint from hoverfly_middleware.json.

if that seems ok, i can dig deeper.

@tommysitu
Copy link
Member

@ns3777k thanks for looking into this. But I think the problem is that some multi-file scripts may not work after being moved to a temp folder due to file path changes. However if this is not an issue, we can add something simple to support it, as you mentioned, a new flag to support loading a directory. For the entry point, you can just pass it through the --script flag, assuming that it's relative to the root folder.

For example:

hoverctl middleware --binary node --script 'main.js` --root-folder `/home/my-middleware`

where main.js is located at /home/my-middleware/main.js

Provided all the files don't reference each other with an absolute path, they should be ok after being moved as well, but I could be too optimistic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants