cloudcmd: /console/console.js 404 when using prefix
Hi,
When I set prefix to /cloudcmd and press the console button, devtool shows a 404 for /cloudcmd/console/console.js.
The cause is that cloudcmd is prepending prefix to "/console" as prefix for console-io:
https://github.com/coderaiser/cloudcmd/blob/v11.5.3/server/cloudcmd.js#L143-L146
When it goes to console-io,
https://github.com/cloudcmd/console-io/blob/v9.0.0/server/index.js#L103
it will not work as it seems, because req.url will be "/console/console.js" instead of "/cloudcmd/console/console.js" due to the mounting feature of express. I tried changing prefix + '/console' to '/console' and it works.
I didn’t read further in console-io, so I’m not sure if it’ll break things in console-io. Can you take a look?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 16 (8 by maintainers)
Commits related to this issue
- feature(cloudcmd) add support of express mounting point (#200) — committed to coderaiser/cloudcmd by coderaiser 6 years ago
- feature(console) add support of express mount point (coderaiser/cloudcmd#200) — committed to cloudcmd/console-io by coderaiser 6 years ago
- feature(cloudcmd) add ability to set prefix for web sockets connections with --prefix-socket (#200) — committed to coderaiser/cloudcmd by coderaiser 6 years ago
Regarding
express mount point, there is app.baseUrl. You are right that client side still need to know the prefix, that’s why I say server side:The client code doesn’t need change the way they work. They keep prepending the prefix when they request resources, it’s just no longer specified by the user of the middleware. I believe the current way this middleware works has the same effect of mounting in most cases, but there’s still some use cases I can think of where it does not satisfy:
/${name}, and expect them to work. It doesn’t know theprefixway.app.use(['/cloudcmd', '/admin'], cloudcmd({..})). Theprefixway doesn’t benefit from it.I’m not familiar with the client code right now. It’s possible that I missed something. 😄
You didn’t reproduce it because you’re running it as a standalone app, by executing
cloudcmd --prefix /cloudcmd, or using it as a middleware at the root path. However, as I mentioned above, when you use the mounting feature of express with cloudcmd, this issue comes in, because express strips thebaseUrlfor you. I highly recommend making cloudcmd work with mounting if you offer its functionality as a middleware, because it’s a very common pattern in express. With it you allow the middleware to work on any path without telling it the prefix. To repro the issue, use the following code:Currently it only works by:
I recommend it to be:
It not only makes it easier to use, but also easier to implement, I guess, because you only deal with logical paths within your middleware. You can eliminate most of the
prefixtricks in server side source code down the stack(console-io, etc.) I believe. I appreciate it if you can consider my advice.