mountebank icon indicating copy to clipboard operation
mountebank copied to clipboard

Mountebank not working when bundled

Open SuperOleg39 opened this issue 4 years ago • 0 comments

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:

  1. errorhandler middleware 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
  2. mountebank hardcode path to templates here, error example - Error: Failed to lookup view "imposters" in views directory "http:/localhost:4000/dist/server/views"
  3. mountebank hardcode path to static resources here, impossible to load working HTML on different application endpoint
  4. (low priority, ease to fix)express view try to require ejs on GET request to /imposters, use dynamic require and webpack can't bundle ejs module, 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:

  1. Remove errorhandler or require it only on development mode
  2. Don't have a solution =(
  3. Add option publicPath to mountebank
  4. Require ejs manually

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.

SuperOleg39 avatar May 27 '21 13:05 SuperOleg39