Unable to preview-docs from Docker
Describe the bug I would like to use the Docker container to preview the documentation instead of using directly npx
To Reproduce Steps to reproduce the behavior:
- Assuming you have a valid
openapi.yamlin the same directory - Run this command:
docker container run -t --rm -v ${PWD}:/spec -p 8080:8080 redocly/openapi-cli preview-docs /spec/openapi.yaml - See error
Expected behavior The Docker container exposing the preview documention
Logs
TypeError: o is not a constructor
at Object.t.startWsServer (/bin/openapi-cli:43:129218)
at Object.<anonymous> (/bin/openapi-cli:43:21717)
at Generator.next (<anonymous>)
at s (/bin/openapi-cli:43:19069)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
openapi-cli Version(s)
1.0.0-beta.40
Node.js Version(s)
v15.12.0
Additional context Using the provided Dockerfile in this repo, works as expected outside Docker
This bug is likely introduced in PR #177.
The /bin/openapi-cli file in the Dockerfile is compiled by Webpack
https://github.com/Redocly/openapi-cli/blob/360c865d23668c46cad9ee63677fce54925ce238/Dockerfile#L10-L15
However, the simple-websocket is configured to be null-loaded
https://github.com/Redocly/openapi-cli/blob/360c865d23668c46cad9ee63677fce54925ce238/webpack.config.ts#L20-L30
Therefore, the SocketServer will become {} when compiled by Webpack, hence the error TypeError: o is not a constructor.
https://github.com/Redocly/openapi-cli/blob/360c865d23668c46cad9ee63677fce54925ce238/packages/cli/src/commands/preview-docs/preview-server/server.ts#L5
https://github.com/Redocly/openapi-cli/blob/360c865d23668c46cad9ee63677fce54925ce238/packages/cli/src/commands/preview-docs/preview-server/server.ts#L65-L66
Pinging @RomanHotsiy and @knidarkness to raise awareness of this issue.
Fixed in #364 (merged into master in commit 128aea923bf03437945f29392cd3cd2e94963d59)
Great job guys !