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

@expraptor/web

v1.0.6

Published

Simple library to deploy node express using typescript decorators

Downloads

3

Readme

@expraptor-web

A node js package that allow you to use typescript decorator to deploy your node express app.

Installation

$ npm install @expraptor/web

tsconfig.json:

{
  "compilerOptions": {
    "experimentalDecorators": true
  }
}

Usage

Simple Usage

import web from "@expraptor/web";

@web.Router({
    path: "/client"
})
export default class ClientRoute {
    @web.GET({
        path: ""
    })
    public static list(): string {
        return "Hello from /client";
    }
    @web.GET({
        path: "/:id"
    })
    public static get(@web.Path() id: number): Client {
        return `Hello from /client/${id}`;
    }
}
const server = new web.Server(3000);
server.register(ClientRoute);
server.start();

Use view engine ex: ejs.

$ npm install ejs

home.ejs in views dir

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Home</title>
</head>
<body>
<div class="container mt-2">
    <header>
        <h2>Welcome <%= name %></h2>
    </header>
    <section>
        <h2>Here is the body</h2>
        <p>
            <%= body %>!
        </p>
    </section>
    <footer>
        <h2>Here is the footer</h2>
    </footer>
</div>
</body>
</html>
import web from "@expraptor/web";

@web.Router({
    path: ""
})
export default class Home {

    @web.GET({
        path: ""
    })
    // @ts-ignore
    public static home(): web.View {
        const view = new web.View("home");
        view.set("name", "Me");
        view.set("body", "Hello all");
        return view;
    }
}
const server = new web.Server(3000);
server.setViewEngine("ejs", "./views");
server.register(Home);
server.start();

Enable security using @expraptor/security

$ npm install @expraptor/security
$ npm install express-session
import security from "@expraptor/security";
import web from "@expraptor/web";
import session from "express-session";
import express from "express";

/**
 * Class to configure the security 
 */
class Security implements security.SecurityConfigurator {

    auth(builder: security.auth.AuthenticationBuilder) {
        builder.inMemoryUser()
            .addUser("john", "john", ["ADMIN"], [])
            .addUser("jane", "jane", [], ["CLIENT"])
            .addUser("bob", "secret", [], []);
    }

    http(http: security.http.HttpSecurity) {
        http.authorize()
            .requestMatcher("/", "/client/**").permitAll()
            .anyRequest().authenticated();
    }
}

@web.Router({
    path: "/client",
    middlewares: [express.json()]
})
class ClientRoute {

    @web.GET({
        path: ""
    })
    @security.PreAuthorize("$.hasAuthority('CLIENT')")
    public static list(): string {
        return "Cool you have CLIENT authority.";
    }

    @web.GET({
        path: "/:id"
    })
    @security.PreAuthorize("$.hasRole('ADMIN') OR $.hasAuthority('CLIENT')")
    public static get(@web.Path() id: number): string {
        return "";
    }
}

@web.Router({
    path: "/",
    middlewares: [express.json()]
})
class HomeRoute {

    @web.GET({
        path: ""
    })
    public static home(): string {
        return "Welcome home";
    }
}

const server = new web.Server(3000);
// Use session authentication 
server.use(session({secret: "secret"}));
// Use urlencoded because we ara using default login form
server.use(express.urlencoded());
server.enableSecurity(new Security());
server.register(HomeRoute);
server.register(ClientRoute);
server.start();