@lcdev/server
v0.3.2
Published
Common base server with minimal functionality
Downloads
2
Keywords
Readme
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 });
}