Nested Parenthetical Madness

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

    Install

    npm i burnserve

    DownloadsWeekly Downloads

    35

    Version

    1.0.7

    License

    MIT

    Unpacked Size

    21.8 kB

    Total Files

    18

    Last publish

    Collaborators

    • der_googler