npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

resroute

v1.0.51

Published

Quick [Preact](https://preactjs.com) server that supports SSR. Uses [JellyFish Router](https://codeberg.org/hkau/jellyfish-router) as a base.

Downloads

13

Readme

resroute

Quick Preact server that supports SSR. Uses JellyFish Router as a base.

Installation

Resroute requires the Bun runtime to run.

npm i resroute
bun a resroute

Usage

  1. Create a .env file, see the example .env file provided in the root of this repository for an easy example

  2. Start server and define routes, see example/index.test.ts as an example

    • Routes are defined using the RegisterRoute function

      import { Serve, RegisterRoute } from "resroute";
      
      // register routes
      RegisterRoute("/", ["GET"]);
    • Routes must be registered before they will work

RegisterRoute

All routes must be registered before they will serve content (besides all content under /_static)

RegisterRoute tells the server which routes you expect to work on your server.

function RegisterRoute(
    path: string,
    supportedMethods: Method[],
    supportOldRouting?: boolean,
    returnRoute: boolean
): void;

Old Routing

Sometimes, routes such as /blog/[slug] might not work properly. You can tell a route to use old routing (routing from JellyFish Router) if you want a simple catch-all route. When using old routing, all paths under a route will be directed to :page.tsx, the blog example directs all paths under /blog to the route /blog/:page.tsx. If there is an index.tsx file present and there is a separate route that does not support old routing on the same path, that will be used.

For example:

// example/index.test.ts
RegisterRoute("/blog", ["GET"]);
RegisterRoute("/blog", ["GET"], true);

If the user requested /blog/test, they would be given /blog/:page.tsx. If they requested /blog, they would be given /blog/index.tsx.

The match.params object will be replaced with an array containing every path after the old route name.

Return Response

Setting returnResponse to true while registering your route allows you to return a response object instead of JSX.

For example:

// example/index.test.ts
RegisterRoute("/jsonreturn", ["GET"], true, true);

// example/jsonreturn.tsx
export default function JSONReturnTest() {
    return new Response(
        JSON.stringify({
            "Content-Type": "application/json; charset=utf-8",
        }),
        {
            headers: {
                "Content-Type": "application/json; charset=utf-8",
            },
        }
    );
}

Example Page

// layout: /pages/blog/[slug].tsx
export default function Post(match: any) {
    return <h1>{match.params.slug}</h1>;
}

If using old routing, this would give the same result:

// layout: /pages/blog/:page.tsx
export default function Post(match: any) {
    return <h1>{match.params[0]}</h1>;
}