oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.1k stars 2.77k forks source link

built-in web server #12986

Open sudo-barun opened 3 months ago

sudo-barun commented 3 months ago

What is the problem this feature would solve?

Bun does not have built-in web server that can be run through CLI.

While there are many package in NPM to create web server, it is a hassle to decide on which package to install, especially for beginners.

Other programming language runtimes provide option in CLI to run web server:

  1. Python: python3 -m http.server
  2. PHP: php -S localhost:8000

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

It would be great if Bun provides built-in web server that can be run through CLI.

bun serve . --port 8080

What alternatives have you considered?

Although Deno does not have built web server, it does provide standard package to run web server:

   deno install --allow-net --allow-read jsr:@std/http@1.0.0-rc.5/file-server
   file-server .

Bun can also provide such standard package.

But, I still prefer having option in bun CLI instead of introducing one extra executable.

ghost commented 3 months ago

https://github.com/vercel/serve

bunx serve

sudo-barun commented 3 months ago

@zoto-ff serve is not a built-in feature. It is a npm package. bun has to download serve (if not downloaded already) before bunx serve works.

kumikumi commented 1 month ago

+1 for this

Right now I'm using

bun install --global http-server
http-server

Given that Bun has its own built-in web server, it would make sense to expose it as a command, so that you could serve static files without a third-party solution.

Similarly to the http-server command, I think bun serve without arguments should be enough to serve static files from the current directory.