New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

hapiest

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapiest

Decorators for hapi 17+

latest
Source
npmnpm
Version
1.0.32
Version published
Maintainers
1
Created
Source

[Hapiest] Beautiful code is what I seek.

NPM version

https://medium.com/@junaid1460/hapiest-7f3a184604b7 read use cases here.


npm i hapiest@latest

Requirements

hapi 17+ typescript 3 (es6)

Usage

import { Server } from "hapi";
import { Hapiest } from "hapiest";

@Hapiest.Routes({ baseUrl: "api", auth: false })
class AdminRoutes extends Hapiest.HapiestRoutes {
    @Hapiest.get({ path: "" }) // Path:  /api
    public api(args: Hapiest.HapiestParams) {
        return "base\n";
    }

    @Hapiest.get() // Path: /api/getTest
    public getTest({
        request
    }: Hapiest.HapiestParams<Hapiest.HapiestRequest<{ username: string }>>) {
        return `hey, what's up? I know type of payload ${request.payload.username}\n`;
    }

    @Hapiest.get({ path: "name" }) // Path: /api/name
    public async getit(args: Hapiest.HapiestParams) {
        return "junaid\n";
    }
}

class MyFirstHapiestModule extends Hapiest.HapiestModule {
    public routeSets = [AdminRoutes];
    public baseUrl = "dev";
    public auth = "simple"; // Make sure that you registered auth plugin
}

class ModuleWithNoAuth extends Hapiest.HapiestModule {
    public routeSets = [AdminRoutes];
    public baseUrl = "test";
    public auth: false = false;
}

const hapiServer = new Server({
    host: "0",
    port: 8000,
    routes: { cors: true }
});

async function start() {
    await hapiServer.register({
        plugin: require("hapi-auth-basic")
    });
    hapiServer.auth.strategy("simple", "basic", {
        validate: () => true
    });
    hapiServer.route(new MyFirstHapiestModule().getRoutes());
    hapiServer.route(new ModuleWithNoAuth().getRoutes());

    await hapiServer.start().then(e => {
        console.log("server started");
        const routesText = hapiServer
            .table()
            .map(route => {
                return `${route.method}: (${JSON.stringify(
                    route.settings.auth
                ) || "No auth"}) ${route.path}`;
            })
            .join("\n");
        console.log(routesText);
        // server started
        // get: ({"strategies":["simple"],"mode":"required"}) /dev/api/api
        // get: ({"strategies":["simple"],"mode":"required"}) /dev/api/getTest
        // get: ({"strategies":["simple"],"mode":"required"}) /dev/api/name
        // get: (false) /test/api/api
        // get: (false) /test/api/getTest
        // get: (false) /test/api/name
    });
}

start();

Keywords

hapi

FAQs

Package last updated on 05 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts