@cordisjs/plugin-server
Advanced tools
Comparing version 0.2.4 to 0.2.5
@@ -7,3 +7,3 @@ import { Context, Service } from 'cordis'; | ||
import KoaRouter from '@koa/router'; | ||
import Koa from 'koa'; | ||
import Koa, { Middleware } from 'koa'; | ||
export interface ListenOptions { | ||
@@ -51,2 +51,3 @@ host: string; | ||
_koa: Koa<Koa.DefaultState, Koa.DefaultContext>; | ||
_body: Middleware; | ||
host: string; | ||
@@ -53,0 +54,0 @@ port: number; |
{ | ||
"name": "@cordisjs/plugin-server", | ||
"description": "Server plugin for cordis", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"type": "module", | ||
@@ -6,0 +6,0 @@ "main": "lib/index.cjs", |
import { Context, Service } from 'cordis' | ||
import { MaybeArray, remove, trimSlash } from 'cosmokit' | ||
import { makeArray, MaybeArray, remove, trimSlash } from 'cosmokit' | ||
import { createServer, Server as HTTPServer, IncomingMessage } from 'node:http' | ||
@@ -10,3 +10,3 @@ import { pathToRegexp } from 'path-to-regexp' | ||
import KoaRouter from '@koa/router' | ||
import Koa from 'koa' | ||
import Koa, { Middleware } from 'koa' | ||
import { listen } from './listen' | ||
@@ -72,2 +72,3 @@ | ||
public _koa = new Koa() | ||
public _body: Middleware | ||
@@ -84,3 +85,3 @@ public host!: string | ||
// create server | ||
this._koa.use(koaBody({ | ||
this._body = koaBody({ | ||
multipart: true, | ||
@@ -91,3 +92,3 @@ jsonLimit: '10mb', | ||
includeUnparsed: true, | ||
})) | ||
}) | ||
this._koa.use(this.routes()) | ||
@@ -163,2 +164,6 @@ this._koa.use(this.allowedMethods()) | ||
register(...args: Parameters<KoaRouter['register']>) { | ||
args[2] = makeArray(args[2]) | ||
if (!args[2][0][Symbol.for("noParseBody")]) { | ||
args[2].unshift(this._body); | ||
} | ||
const layer = super.register(...args) | ||
@@ -165,0 +170,0 @@ this.ctx.scope.disposables.push(() => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
32316
695