burnserve
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

BurnServe

This library requires Bun

This library is currently experimental and under development. Everything can CHANGE!

Quickstart

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

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

import { BurnServe } from "./../src";
import { PPContext } from "./PPContex";

const app = new BurnServe<PPContext>({
  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

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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.7
    1
    • latest

Version History

Package Sidebar

Install

npm i burnserve

Weekly Downloads

1

Version

1.0.7

License

MIT

Unpacked Size

21.8 kB

Total Files

18

Last publish

Collaborators

  • der_googler