🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

@daniellehuisman/koa-base

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@daniellehuisman/koa-base

Koa server with basic middleware

latest
npmnpm
Version
1.3.1
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 {createServer, logger, startServer} from '@danielhuisman/koa-base';
import Router from 'koa-router';
import path from 'path';

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

koa

FAQs

Package last updated on 17 Jan 2024

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