diff --git a/.eslintrc b/.eslintrc index 98f9236ae..9bcdb4688 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,5 +1,6 @@ { "extends": [ - "eslint-config-egg/typescript" + "eslint-config-egg/typescript", + "eslint-config-egg/lib/rules/enforce-node-prefix" ] } diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 60edbce24..ae12488c4 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -12,6 +12,6 @@ jobs: uses: node-modules/github-actions/.github/workflows/node-test.yml@master with: os: 'ubuntu-latest, macos-latest, windows-latest' - version: '18.19.0, 18, 20, 22' + version: '18.19.0, 18, 20, 22, 23' secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/example/extend/Request.ts b/example/extend/Request.ts new file mode 100644 index 000000000..653175d3f --- /dev/null +++ b/example/extend/Request.ts @@ -0,0 +1,23 @@ +import { Request } from '../../src/index.js'; + +const HOST = Symbol('request host'); + +export class CustomRequest extends Request { + get host(): string { + let host = this[HOST] as string; + if (host) { + return host; + } + + if (this.app.proxy) { + host = '127.0.0.1'; + } + const rawHost = host || this.get('host'); + if (!rawHost) { + this[HOST] = ''; + return ''; + } + this[HOST] = rawHost.split(/\s*,\s*/)[0]; + return host; + } +} diff --git a/example/helloworld.cjs b/example/helloworld.cjs index 7eb5bd126..e20c998cb 100644 --- a/example/helloworld.cjs +++ b/example/helloworld.cjs @@ -1,5 +1,5 @@ // eslint-disable-next-line @typescript-eslint/no-var-requires -const { Application } = require('../dist/commonjs/index.js'); +const { Application } = require('..'); const app = new Application(); diff --git a/example/helloworld.mjs b/example/helloworld.mjs index d805b3373..2efc9a3e9 100644 --- a/example/helloworld.mjs +++ b/example/helloworld.mjs @@ -1,4 +1,4 @@ -import { Application } from '../dist/esm/index.js'; +import { Application } from '..'; const app = new Application(); diff --git a/src/application.ts b/src/application.ts index d069bdb9b..12b770c26 100644 --- a/src/application.ts +++ b/src/application.ts @@ -17,7 +17,7 @@ import { Response } from './response.js'; import type { ContextDelegation } from './context.js'; import type { CustomError, AnyProto } from './types.js'; -const debug = debuglog('@eggjs/koa:application'); +const debug = debuglog('@eggjs/koa/application'); export type ProtoImplClass = new(...args: any[]) => T; export type Next = () => Promise; @@ -29,6 +29,7 @@ export type MiddlewareFunc = _MiddlewareFunc & { _name?: string }; * Inherits from `Emitter.prototype`. */ export class Application extends Emitter { + [key: symbol]: unknown; /** * Make HttpError available to consumers of the library so that consumers don't * have a direct dependency upon `http-errors` diff --git a/src/context.ts b/src/context.ts index 7be730311..0d3175b1f 100644 --- a/src/context.ts +++ b/src/context.ts @@ -11,6 +11,7 @@ import type { Response } from './response.js'; import type { CustomError, AnyProto } from './types.js'; export class Context { + [key: symbol]: unknown; app: Application; req: IncomingMessage; res: ServerResponse; diff --git a/src/request.ts b/src/request.ts index 7bf09df1c..d8929fac5 100644 --- a/src/request.ts +++ b/src/request.ts @@ -13,6 +13,7 @@ import type { ContextDelegation } from './context.js'; import type { Response } from './response.js'; export class Request { + [key: symbol]: unknown; app: Application; req: IncomingMessage; res: ServerResponse; diff --git a/src/response.ts b/src/response.ts index 345fc35aa..c3581756a 100644 --- a/src/response.ts +++ b/src/response.ts @@ -17,6 +17,7 @@ import type { ContextDelegation } from './context.js'; import type { Request } from './request.js'; export class Response { + [key: symbol]: unknown; app: Application; req: IncomingMessage; res: ServerResponse;