Code Monkey home page Code Monkey logo

serve-static-bun's Introduction

Hello there ๐Ÿ‘‹

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-bun's People

Contributors

gornostay25 avatar jakobbouchard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

lazuee

serve-static-bun's Issues

using `.` as the directory causes weird issues

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

Support for absolute paths

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. ๐Ÿค”

You don't need to use arraybuffer and await

https://github.com/jakobbouchard/serve-static-bun/blob/ab71176028b0c49fc94dc3758e038c9601d486b6/lib/serve-static.ts#L143-L157

		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

https://github.com/gornostay25/svelte-adapter-bun/blob/b3e7449100216d2e72564d137c6c682c42c01507/src/sirv.js#L99-L102

Remove process.cwd() as root folder

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" }));

Add more options

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.