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

@kapeta/sdk-server

v4.0.5

Published

Express server for Kapeta SDK

Downloads

1,052

Readme

Kapeta NodeJS Server

This provides an HTTP server for Kapeta blocks.

It wraps the express server and provides plumbing for the blocks.

The Server class is implemented in index.ts.

Features

Frontend

Serves the frontend assets for the block when applicable.

Uses webpack to build the frontend assets and serves them from memory in dev mode - with hot reloading. Will serve the assets from the dist folder in production mode.

See the Server.configureFrontend() method for details.

The webpack server is implemented in src/webpack.ts.

Templates

The templates are managed via express template engine. In short, express needs to know where the views live, and which renderer to use.

Make sure to include all parameters in the template, otherwise the block will not work as expected.

// Set up webpack middleware and render methods
const DIST_DIR = Path.resolve(__dirname, "../dist");
const webpackConfig = require("../webpack.development.config");
server.configureFrontend(DIST_DIR, webpackConfig);

// Set up templating
const hbs = createHandlebars({
    extname: '.hbs',
    defaultLayout: false,
    helpers: {
        // Recommended helper to serialize values in handlebars
        toJSON: (obj: any) => JSON.stringify(obj),
    },
});
server.express().engine('hbs', hbs.engine);
server.express().set('views', Path.resolve(__dirname, "../templates"));
server.express().set('view engine', 'hbs');

server.get('/', async (req, res, next) => {
    // render the main template e.g. templates/main.hbs
    await res.renderPage('main');
});

Template parameters include:

  • baseURL usually sets the HTML base tag in the template
  • scripts is a list of <script> tags to load the app JS bundle.
  • styles is a list of <style> tags to load the app CSS bundle.

Healthcheck

The server provides a standard Kapeta healthcheck endpoint at /.kapeta/health.

You can disable this using the disableHealthcheck option.

You can also override the default health check by subclassing the Server and overriding the configureHealthCheck method.

Catch-all Handler

Will add a catch-all route that will return a 418 for any request that does not match a route.

This makes it easier to determine if a request is not being handled by the server.

You can disable the catch-all route using the disableCatchAll option.

You can also override the default catch all by subclassing the Server and overriding the configureCatchAll method.

Error handling

The server will catch any errors thrown by the routes and return a consistent response. If the error contains a "statusCode" property it will be used as the response status code.

You can disable this using the disableErrorHandling option.

You can also override the default error handling by subclassing the Server and overriding the configureErrorHandler method.