Skip to content

Support a baseUrl in the client html, js, css generated by the devServer #19845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ggmath-estia opened this issue May 22, 2025 · 3 comments
Open
Labels
bake:dev hot-reloading dev server for client+server applications enhancement New feature or request

Comments

@ggmath-estia
Copy link

What is the problem this feature would solve?

The devServer is really awesome and could be a game changer.

However it the client-side files are curretly refering to resources under the path "/_bun" which prevents us from serving the app on a sub-path.

What is the feature you are proposing to solve the problem?

Setting a baseUrl would allow serving the app behind a reverse-proxy on a sub-path. This is mostly used for servers like Kubernetes hosting multiple applications.

Having a baseUrl would also allow us to simply transform the absolute "/_bun" into "./_bun" that would fit our needs.

What alternatives have you considered?

I considered pre-building the clients assets and setting a static file server but is completelly defeats the ease-of-use of the current server philo.

@ggmath-estia ggmath-estia added the enhancement New feature or request label May 22, 2025
@RiskyMH RiskyMH added the bake:dev hot-reloading dev server for client+server applications label May 22, 2025
@Jarred-Sumner
Copy link
Collaborator

Jarred-Sumner commented May 25, 2025

Can you try setting publicPath = "http://localhost:3000/my-custom-path/" in [serve] in bunfig.toml?

bun/src/bunfig.zig

Lines 705 to 710 in 7dc58e0

if (serve_obj.get("publicPath")) |public_path| {
if (public_path.asString(allocator)) |value| {
this.bunfig.serve_public_path = value;
}
}

@ggmath-estia
Copy link
Author

ggmath-estia commented May 26, 2025

Thanks for the reply, I tried many things unsuccessfully:

[serve]
publicPath = "http://localhost:3000/my-custom-path/"
[serve.static]
publicPath = "http://localhost:3000/my-custom-path/"
[serve]
publicPath = "/my-custom-path"
[serve.static]
publicPath = "/my-custom-path"
bun --hot --publicPath="http://localhost:3000/my-custom-path/" server/main.js
bun --hot --publicPath="/my-custom-path" server/main.js

I did not manage to have it work the expected way for 2 reasons:

  1. the dev server still served the home page on / rather than on /my-custom-path
  2. the assets requested by the web page in the browser were being requested at /_bun/...(.css,.js) rather than at /my-custom-path/_bun/...(.css,.js) (from the network tab in the web console)

Maybe it is working for the build and not the run command I currently use ?

bun --hot server/main.js

@paperclover
Copy link
Contributor

https://github.com/oven-sh/bun/blob/main/src/bake/DevServer.zig#L1086

note that it cannot be ./_bun as tempting as that is, because sometimes the internal state does not know exactly where it is being served. for example, the same HTML file placed on multiple routes, or a wildcard route. the HTML must specify an absolute path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bake:dev hot-reloading dev server for client+server applications enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants