Skip to content

Lightweight version of Alosaur. Specially designed to work with deno deploy.

Notifications You must be signed in to change notification settings

alosaur/alosaur-lite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Alosaur-lite

Lightweight version of Alosaur (2.4kb, gzip, one file) without dependencies. Specially designed to work with deno deploy.

Demo (Markdown render)

TODO:

  • Controllers
  • Actions methods (GET, POST, etc)
  • Serve static files
  • Render pages (React jsx, markdown files)

Example:

Full example

import {App, Content, Controller, Get, Param, QueryParam} from "https://deno.land/x/alosaur_lite/dist/mod.js";

@Controller()
export class MainController {
  @Get()
  indexPage() {
    return "index page";
  }

  @Get("/home")
  homePage() {
    return "home page";
  }

  @Get("/json")
  jsonPage() {
    return {data: "test"};
  }

  @Get("/not")
  notPage() {
    return Content("Not authorized", 401);
  }

  @Get("/page/:id")
  paramPage(@Param("id") id: string, @QueryParam('filter') filter: string) {
    return `Id: ${id} Filter: ${filter}`;
  }
}

const app = new App({
  controllers: [MainController],
});

addEventListener("fetch", (event: FetchEvent) => {
  event.respondWith(app.handleRequest(event.request));
});

How to serve static files?

app.useStatic({
      root: import.meta.url,
      index: "index.html",
      baseRoute: "/www/",
    } // or undefined for default route /
);

How render pages?

Example

app.useViewRender({
  type: "react",
  basePath: `/views/`,
  getBody: async (path: string, model: Object, config: any) =>
      await getPage(path, model),
});

How render markdown files?

Example | Demo

About

Lightweight version of Alosaur. Specially designed to work with deno deploy.

Resources

Stars

Watchers

Forks

Packages

No packages published