https://github.com/dergoogler/burnserve
Fast, zero dependency HTTP Server for Bun.js runtime
https://github.com/dergoogler/burnserve
Last synced: 5 months ago
JSON representation
Fast, zero dependency HTTP Server for Bun.js runtime
- Host: GitHub
- URL: https://github.com/dergoogler/burnserve
- Owner: DerGoogler
- License: mit
- Created: 2022-08-19T11:47:15.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-08-21T18:02:29.000Z (almost 4 years ago)
- Last Synced: 2025-06-01T07:51:06.486Z (about 1 year ago)
- Language: TypeScript
- Size: 120 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BurnServe
This library requires [Bun](https://bun.sh)
> This library is currently experimental and under development. Everything can CHANGE!
## Quickstart
```ts
import BurnServe from "burnserve";
const app = new BurnServe();
app.get("/", ctx => {
ctx.sendHTML("lol");
});
app.get("/test", ctx => {
ctx.sendHTML("You're on a test page");
});
app.get(/\/public\/.*/, ctx => {
ctx.sendHTML("Public folder");
});
app.get(/\/ab(cd)?e/, ctx => {
ctx.sendHTML("You're on a test page");
});
app.listen(
{
port: 3030,
},
opts => {
console.log(`Server listening on port ${opts.port}`);
}
);
```
## Documentation
## Any routing
The helper `anyRoute` make this possible
```ts
import BurnServe, { anyRoute } from "burnserve";
const app = new BurnServe();
app.get(anyRoute(["test", "public"]), ctx => {
ctx.sendHTML("Hello, world!");
});
// If you don't exclude these path, they won't never show up
app.get("/test", ctx => {
ctx.sendHTML("You're on a test page");
});
// Same here
app.get(/\/public\/.*/, ctx => {
ctx.sendHTML("Public folder");
});
app.listen({
port: 3030,
});
```
## Custom context
**main.ts**
```ts
import { BurnServe } from "./../src";
import { PPContext } from "./PPContex";
const app = new BurnServe({
context: PPContext,
});
// Exclude public from any rotung
app.getAR(["public"], ctx => {
ctx.log("Test log");
ctx.sendHTML("Im' up!");
});
app.get(/\/public\/.*/, ctx => {
ctx.sendHTML("Public folder");
});
app.listen({
port: 3030,
});
```
**PPContext.ts**
```ts
import { Context } from "../src";
export class PPContext extends Context {
public constructor(req: Request) {
super(req);
}
public log(text: string): this {
console.log(text);
return this;
}
}
```