@lcdev/server
TypeScript icon, indicating that this package has built-in type declarations

0.3.2 • Public • Published

Launchcode Server

This is our @lcdev/server helper node package. It's a really simple, barebones setup that can be used piecemeal. Normally, you'll always be using the things in this package.

yarn add @lcdev/server@VERSION

Example usage:

import startApp, { createApp } from '@lcdev/server';

async function main() {
  // you probably want to start with db setup, migrations and seeds

  // creates a koa instance with support for gzip compression, our logging middleware,
  // error propagation from @lcdev/router, and a basic health endpoint
  const app = await createApp({
    // built-in CORS setup
    allowedOrigins: ['*'],
  });

  // naturally, here you can add your own middleware to `app`
  // likely, you'll add routes with @lcdev/router and its `createRouter` function

  // creates a koa server that's listening on the port
  // includes a listener for unhandled promise rejection and exit signals
  await startApp(app, { port: 838 });
}

You can adopt this more piecemeal though, don't worry.

import * as Koa from 'koa';
import { compress, cors, createHealthEndpoint } from '@lcdev/server';
import { createLoggerMiddleware } from '@lcdev/logger';
import { propagateErrors } from '@lcdev/router';

async function main() {
  const app = new Koa();

  app.use(cors(allowedOrigins));
  app.use(compress());

  app.use(propagateErrors(false));

  app.use(createLoggerMiddleware(logger));
  app.use(createHealthEndpoint());

  // creates a koa server that's listening on the port
  // includes a listener for unhandled promise rejection and exit signals
  await startApp(app, { port: 838 });
}

Readme

Keywords

none

Package Sidebar

Install

npm i @lcdev/server

Weekly Downloads

0

Version

0.3.2

License

UNLICENSED

Unpacked Size

9.63 kB

Total Files

5

Last publish

Collaborators

  • jbrandtlc
  • joelgallant-me
  • servalldev
  • gregnr