Glad to see you here!
- ๐ญ Iโm currently working on 2 npm packages and 1 WordPress plugin.
- ๐ฑ Iโm currently learning video game development!
- ๐ฌ Ask me about video games, tech, web developement, or anything you want!
Serve static files using Bun.serve or Bao.js
Home Page: https://npm.im/serve-static-bun
License: MIT License
import serveStatic from 'serve-static-bun';
const serve = serveStatic('.', {
collapseSlashes: true,
});
Bun.serve({
port: 3000,
fetch: serve,
});
โ bun-rsc git:(main) โ bun run ./src/file.ts
Response (4.50 PB) {
ok: true,
url: "",
status: 200,
statusText: "",
headers: Headers {
"content-type": "text/javascript; charset=utf-8",
},
redirected: false,
bodyUsed: false,
FileRef ("/Users/luna/code/imlunahey/bun-rsc/.//build/_client.js") {
type: "text/javascript;charset=utf-8"
}
}
[1] 19614 segmentation fault bun run ./src/file.ts
โ bun-rsc git:(main) โ bun run ./src/file.ts
[1] 19658 segmentation fault bun run ./src/file.ts
โ bun-rsc git:(main) โ ls -lah /Users/luna/code/imlunahey/bun-rsc/.//build/_client.js
-rw-r--r-- 1 luna staff 1.2M Dec 26 12:41 /Users/luna/code/imlunahey/bun-rsc/.//build/_client.js
Currently if i provide an absolute path it's added to the end of the process.cwd()
which is not what i was expecting at all. ๐ค
if (file.isFile) {
return new Response(file.blob, {
headers: { ...options.headers, "Content-Type": `${getMimeType(file.blob)}; charset=${options.charset}` },
});
}
// If it is a folder and it has an index
if (options.index && indexFile.exists) {
return new Response(indexFile.blob, {
headers: {
...options.headers,
"Content-Type": `${getMimeType(indexFile.blob)}; charset=${options.charset}`,
},
});
}
You don't need to use arraybuffer and await. I used it in my code because oven-sh/bun#616
Hi, fs:node is slow, use Bun special method Bun.file()
check my code https://github.com/gornostay25/svelte-adapter-bun/blob/master/src/sirv.js
It's was modified Sirv library for bun.
check send
method
https://github.com/gornostay25/svelte-adapter-bun/blob/074a26d3b0c300d3d536ad1e9d29e4c77a72209f/src/sirv.js#L63-L103
Why there's a need to add process.cwd()
? Give us the freedom to use absolute path...
https://github.com/jakobbouchard/serve-static-bun/blob/7ed89cd0d142844f73ac158b0fcb351553cc89dc/src/serve-static.ts#L236C1-L236C36
I can't do like this because of that process.cwd()
as root prefix..
import path from "path";
import Bao from "baojs";
import serveStatic from "serve-static-bun";
const app = new Bao();
const staticFolder = path.join(import.meta.dir, "..", "/public");
app.get("/gamefiles/*any", serveStatic(staticFolder, { middlewareMode: "bao", stripFromPathname: "/gamefiles" }));
Non-exhaustive list of options to add (mostly from serve-static)
dotfiles
acceptRanges
lastModified
Options that are not considered or a not priority:
cacheControl
, immutable
, maxAge
: You can set those easily with a header.extensions
: Not considered, I'm not doing pretty URLs, only static files.fallthrough
: Not really possible with the way things are currently, except for maybe with Bao.js.A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.