Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@danielhuisman/koa-base

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@danielhuisman/koa-base

Koa server with basic middleware

  • 1.1.1
  • unpublished
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

koa-base

Koa server with basic middleware.

Middleware

  • Koa Helmet
  • Koa Response Time
  • Koa Conditional GET
  • Koa ETag
  • Koa Compress
  • Koa Session
  • Koa Body Parser
  • Koa JSON
  • Koa Static
  • Winston logger

Installation

yarn add @danielhuisman/koa-base

Usage

import path from 'path';
import {createServer, startServer, logger} from '@danielhuisman/koa-base';
import Router from 'koa-router';

const config = {
    port: 5000,

    session: {
        secret: 'sessionSecret'
    },

    static: {
        serve: process.env.STATIC_SERVE !== 'false',
        path: path.join(__dirname, '..', 'static')
    }
};

(async () => {
    logger.info('Starting application...');

    // Initialize server
    const {server, app} = createServer(config);

    // Initialize router
    const router = new Router();

    // Index route
    router.get('/', async (ctx) => {
        return ctx.success({
            message: 'Hello World!'
        }, 200);
    });

    // Add router
    app.use(router.routes());
    app.use(router.allowedMethods());

    // Handle unknown routes
    app.use(async (ctx, next) => {
        ctx.error(404, 'Not found');
        await next();
    });

    // Start server
    await startServer(config, server);

    logger.info('Started application.');
})();

Keywords

FAQs

Package last updated on 25 Mar 2022

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc