question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

/console/console.js 404 when using prefix

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
panlinacommented, Oct 23, 2018

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:

You can eliminate most of the prefix tricks in server side source code

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:

  • If I have a express app which loads modules as sub apps dynamically, it will have a name for each sub app, mount them at /${name}, and expect them to work. It doesn’t know the prefix way.
  • One can mount an app at several paths. It’s as simple as app.use(['/cloudcmd', '/admin'], cloudcmd({..})). The prefix way doesn’t benefit from it.

I’m not familiar with the client code right now. It’s possible that I missed something. 😄

1reaction
panlinacommented, Oct 22, 2018

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 the baseUrl for 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:

app.use('/cloudcmd', cloudcmd({
	socket,
	config: { prefix: "/cloudcmd" }
}));

Currently it only works by:

app.use('/', cloudcmd({	//or just omit the 1st argument
	socket,
	config: { prefix: "/cloudcmd" }
}));

I recommend it to be:

app.use('/cloudcmd', cloudcmd({	//or just omit the 1st argument
	socket,
	config: { /* no prefix is needed */ }
}));

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 prefix tricks in server side source code down the stack(console-io, etc.) I believe. I appreciate it if you can consider my advice.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Router.use() requires a middleware function but got ...
I am beginner to use socket.io with NodeJS and mocha. ... Non-existent API routes should return 404, not the HTML page router.use((_req, ...
Read more >
Discord.js Per Server Prefix Error "TypeError: Cannot read ...
Hi i was making a per server prefix thing for my discord.js v12 bot using quick.db everything was going well but when using...
Read more >
Router tutorial: tour of heroes - Angular
A wildcard route can navigate to a custom "404 Not Found" component or ... route when the remaining URL begins with the redirect...
Read more >
puppeteer-core@19.4.1 - jsDocs.io
An example of using JavaScript and CSS coverage to get percentage of ... to null if waiting for hidden: true and xpath is...
Read more >
Console features reference - Chrome Developers
It assumes that you're already familiar with using the Console to view logged messages and run JavaScript. If not, see Get Started.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found