Mountebank not working when bundled
Prerequisites
Webpack can bundle server code at single JS file, with all dependencies.
This allows to create Docker container with one server.js bundle, without unnecessary node_modules.
Some framework, NextJS for example, create one complete server bundle.
Problem
After mountebank integration as middleware, at existing application endpoint (see https://github.com/bbyars/mountebank/issues/610 issue), mountebank can be a part of this application server bundle.
At current time, bundled mountebank throw few errors:
-
errorhandlermiddleware try to read files from file system, on run server code, here code, and error example -ENOENT: no such file or directory, open 'http:/localhost:4000/dist/server/public/style.css -
mountebankhardcode path to templates here, error example -Error: Failed to lookup view "imposters" in views directory "http:/localhost:4000/dist/server/views" -
mountebankhardcode path to static resources here, impossible to load working HTML on different application endpoint - (low priority, ease to fix)
expressview try to requireejson GET request to/imposters, use dynamic require and webpack can't bundleejsmodule, more about problem here
Possible solutions
Working solution for 1, 2 and 4 cases - mark mountebank as external for webpack, and copy few libraries from node_modules to Docker container.
Problem here - you need to change Dockerfile.
Another solutions for errors from list:
- Remove
errorhandleror require it only ondevelopmentmode - Don't have a solution =(
- Add option
publicPathtomountebank - Require
ejsmanually
Summary
1, 2 and 4 cases solvable with externals, if nobody have better solution.
But 3 case, looks like we need a publicPath in all cases.