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

@compas/server

Package Overview
Dependencies
Maintainers
1
Versions
196
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@compas/server - npm Package Compare versions

Comparing version 0.0.116 to 0.0.117

8

package.json
{
"name": "@compas/server",
"version": "0.0.116",
"version": "0.0.117",
"description": "Koa server and common middleware",

@@ -18,4 +18,4 @@ "main": "./index.js",

"dependencies": {
"@compas/insight": "0.0.116",
"@compas/stdlib": "0.0.116",
"@compas/insight": "0.0.117",
"@compas/stdlib": "0.0.117",
"formidable": "2.0.0-canary.20200504.1",

@@ -48,3 +48,3 @@ "keygrip": "1.1.0",

},
"gitHead": "240f978002efe57c446650a5de9213961e2c06cb"
"gitHead": "c24054692e907354ddaa42afc6f472599c0b7c4d"
}

@@ -12,3 +12,20 @@ import { isProduction } from "@compas/stdlib";

/**
* @param {GetAppOptions} [opts]
* Create a new Koa instance with default middleware applied.
* Adds the following:
*
* - Health check route on `/_health`
*
* - Log middleware to add the Logger from @compas/insight on `ctx.log`
*
* - Error handler to catch any errors thrown by route handlers
*
* - A 404 handler when no response is set by other middleware
*
* - Default headers to respond to things like CORS requests
*
* @since 0.1.0
* @summary Create a new Koa instance with default middleware applied.
*
* @param {GetAppOptions} [opts={}]
* @returns {Application}
*/

@@ -15,0 +32,0 @@ export function getApp(opts = {}) {

@@ -6,5 +6,7 @@ import { AppError } from "@compas/stdlib";

/**
* Creates a body parser and a body parser with multipart enabled
* Note that koa-body parses url-encoded, form data, json and text by default
* Creates a body parser and a body parser with multipart enabled.
* Note that koa-body parses url-encoded, form data, json and text by default.
*
* @since 0.1.0
*
* @param {IKoaBodyOptions} [bodyOpts={}] Options that will be passed to koa-body

@@ -11,0 +13,0 @@ * @param {IFormidableBodyOptions} [multipartBodyOpts={}] Options that will be passed to

/*
Forked from https://github.com/koajs/compose/tree/06e82e65a368ac12cd6405beaf19fd5d208a1477
Original license: MIT
License file: Unknown
License specifier: https://github.com/koajs/compose/blob/06e82e65a368ac12cd6405beaf19fd5d208a1477/package.json#L29
Forked from https://github.com/koajs/compose/tree/06e82e65a368ac12cd6405beaf19fd5d208a1477
Original license: MIT
License file: Unknown
License specifier: https://github.com/koajs/compose/blob/06e82e65a368ac12cd6405beaf19fd5d208a1477/package.json#L29
*/
/**
* Compose `middleware` returning
* of all those which are passed.
* Compose `middleware` returning of all those which are passed.
*
* @since 0.1.0
*
* @param {Array} middleware
* @returns {Function}
* @returns {Middleware}
*/
export function compose(middleware) {
if (!Array.isArray(middleware))
if (!Array.isArray(middleware)) {
throw new TypeError("Middleware stack must be an array!");
}
for (const fn of middleware) {
if (typeof fn !== "function")
if (typeof fn !== "function") {
throw new TypeError("Middleware must be composed of functions!");
}
}

@@ -27,9 +30,15 @@

return dispatch(0);
function dispatch(i) {
if (i <= index)
if (i <= index) {
return Promise.reject(new Error("next() called multiple times"));
}
index = i;
let fn = middleware[i];
if (i === middleware.length) fn = next;
if (!fn) return Promise.resolve();
if (i === middleware.length) {
fn = next;
}
if (!fn) {
return Promise.resolve();
}
try {

@@ -36,0 +45,0 @@ return Promise.resolve(fn(context, dispatch.bind(null, i + 1)));

@@ -7,2 +7,3 @@ import { Transform } from "stream";

* Log basic request and response information
*
* @param {GetAppOptions.logOptions} options

@@ -9,0 +10,0 @@ */

import { isNil } from "@compas/stdlib";
/**
* @param ctx
* Send a `StoreFile` instance from @compas/store as a `ctx` response.
* Handles byte range requests as well. May need some improvements to set some better
* cache headers.
*
* @since 0.1.0
*
* @param {Context} ctx
* @param {SendFileItem} file
* @param {GetStreamFn} getStreamFn
* @returns {Promise<undefined>}
*/

@@ -8,0 +15,0 @@ export async function sendFile(ctx, file, getStreamFn) {

@@ -6,9 +6,12 @@ import { environment, isNil, isProduction, merge, uuid } from "@compas/stdlib";

/**
* Session middleware
* Requires process.env.APP_KEYS
* To generate a key use something like
* node -e "console.log(require('crypto').randomBytes(32).toString('base64'))"
* Session middleware. Requires process.env.APP_KEYS to be set. To generate a key use
* something like:
* `node -e "console.log(require('crypto').randomBytes(32).toString('base64'))"`.
* This also accepts the session store as provided by `@compas/store`.
*
* @since 0.1.0
*
* @param {Application} app
* @param {SessionOptions} opts KoaSession options
* @returns {Middleware}
*/

@@ -64,5 +67,3 @@ export function session(app, opts) {

*
* @param {SessionStore} store
* @param {string} key
* @param {*} cookieOpts
* @param {{ store: SessionStore, key: string, } & SessionOptions} opts
*/

@@ -69,0 +70,0 @@ function wrapStoreCalls({ store, key, ...cookieOpts }) {

/**
* Open the provided Koa app on a random port, and use the port to set the 'baseURL' on
* the provided Axios instance.
*
* @since 0.1.0
*
* @param {Application} app
* @param {AxiosInstance} axios
* @returns {Promise<undefined>}
*/

@@ -27,4 +33,8 @@ export async function createTestAppAndClient(app, axios) {

/**
* Close the test app as created by `createTestAppAndClient`.
*
* @since 0.1.0
*
* @param {Application} app
* @returns {Promise<void>}
* @returns {Promise<undefined>}
*/

@@ -31,0 +41,0 @@ export function closeTestApp(app) {

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