diff --git a/index.js b/index.js index 03ac9eb..198837d 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,42 @@ export default class Controller { #auth = null + get method() { + return this.request.method + } + + get host() { + return this.request.host + } + + get hostname() { + return this.request.hostname + } + + get ua() { + return this.request.headers['user-agent'] + } + + get jwt() { + return { + result: this.#auth, + sign: data => { + let { __mix_key__ } = this.request + return this.context.$$jwt.sign(data, __mix_key__) + }, + verify: () => { + this.#auth = null + let token = this.request.header('authorization') + let { __mix_key__ } = this.request + + if (token) { + this.#auth = this.context.$$jwt.verify(token, __mix_key__) + } + return this.#auth + } + } + } + // 定义一个模板变量 assign(key, val) { if (this.context.$$views) { @@ -39,26 +75,6 @@ export default class Controller { } } - get jwt() { - return { - result: this.#auth, - sign: data => { - let { __mix_key__ } = this.request - return this.context.$$jwt.sign(data, __mix_key__) - }, - verify: () => { - this.#auth = null - let token = this.request.header('authorization') - let { __mix_key__ } = this.request - - if (token) { - this.#auth = this.context.$$jwt.verify(token, __mix_key__) - } - return this.#auth - } - } - } - // cookie读写 cookie(key, val, opt) { if (arguments.length === 1) { diff --git a/package.json b/package.json index 210fc0b..d3128c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gm5/controller", - "version": "1.0.0", + "version": "2.0.0", "type": "module", "description": "控制器基类。", "main": "index.js",