@aomex/web
Advanced tools
Comparing version 0.0.11 to 0.0.12
# @aomex/web | ||
## 0.0.12 | ||
### Patch Changes | ||
- [`f14eb5f`](https://github.com/aomex/aomex/commit/f14eb5fe7bf06e1e2f64d45e3546c96d6079a2f1) Thanks [@geekact](https://github.com/geekact)! - feat(web): add getters to request | ||
- [`7d923cf`](https://github.com/aomex/aomex/commit/7d923cf971b6a23d50113ab104c67041c6489053) Thanks [@geekact](https://github.com/geekact)! - feat(web)!: do not transform querystring value to array | ||
- [`3c5ad4e`](https://github.com/aomex/aomex/commit/3c5ad4e2f34be7da54c8b63f6fd4b88fd1e593c4) Thanks [@geekact](https://github.com/geekact)! - chore(web): upgrade qs from 6.11.0 to 6.11.1 | ||
- [`6154ee5`](https://github.com/aomex/aomex/commit/6154ee5ed500984f969d4c335ac3ad800c739937) Thanks [@geekact](https://github.com/geekact)! - refactor(web): replace lru-cache to memory-cache | ||
- [`a0fd49e`](https://github.com/aomex/aomex/commit/a0fd49ef276c05f312257521c75887458857bbb7) Thanks [@geekact](https://github.com/geekact)! - refactor(web): rename request.path to request.pathname | ||
- Updated dependencies [[`92273f9`](https://github.com/aomex/aomex/commit/92273f913e38543f34f41ec5941ff43b6e1caaa9)]: | ||
- @aomex/core@0.0.11 | ||
## 0.0.11 | ||
@@ -4,0 +21,0 @@ |
@@ -69,3 +69,3 @@ import { Chain, PureChain, PureMiddlewareToken, Next, Middleware, OpenAPI, Validator, TransformedValidator, ValidateResult, ValidatorOptions } from '@aomex/core'; | ||
type UpperStringHeaderKeys = UpperExternalStringHeaderKeys | UpperOfficialStringHeaderKeys; | ||
type LowerExternalStringHeaderKeys = 'accept-encoding' | 'x-forwarded-for' | 'x-forwarded-proto' | 'x-forwarded-host' | 'x-real-ip' | 'access-control-request-private-network' | 'access-control-allow-private-network'; | ||
type LowerExternalStringHeaderKeys = 'accept-encoding' | 'x-forwarded-for' | 'x-forwarded-proto' | 'x-forwarded-host' | 'x-real-ip' | 'access-control-request-private-network' | 'access-control-allow-private-network' | ':authority'; | ||
type UpperExternalStringHeaderKeys = 'Accept-Encoding' | 'X-Forwarded-For' | 'X-Forwarded-Proto' | 'X-Forwarded-Host' | 'X-Real-IP' | 'Access-Control-Request-Private-Network' | 'Access-Control-Allow-Private-Network'; | ||
@@ -157,3 +157,9 @@ type UpperOfficialStringHeaderKeys = 'Accept' | 'Accept-Language' | 'Accept-Patch' | 'Accept-Ranges' | 'Access-Control-Allow-Credentials' | 'Access-Control-Allow-Headers' | 'Access-Control-Allow-Methods' | 'Access-Control-Allow-Origin' | 'Access-Control-Expose-Headers' | 'Access-Control-Max-Age' | 'Access-Control-Request-Headers' | 'Access-Control-Request-Method' | 'Age' | 'Allow' | 'Alt-Svc' | 'Authorization' | 'Cache-Control' | 'Connection' | 'Content-Disposition' | 'Content-Encoding' | 'Content-Language' | 'Content-Length' | 'Content-Location' | 'Content-Range' | 'Content-Type' | 'Cookie' | 'Date' | 'Etag' | 'Expect' | 'Expires' | 'Forwarded' | 'From' | 'Host' | 'If-Match' | 'If-Modified-Since' | 'If-None-Match' | 'If-Unmodified-Since' | 'Last-Modified' | 'Location' | 'Origin' | 'Pragma' | 'Proxy-Authenticate' | 'Proxy-Authorization' | 'Public-Key-Pins' | 'Range' | 'Referer' | 'Retry-After' | 'Sec-Websocket-Accept' | 'Sec-Websocket-Extensions' | 'Sec-Websocket-Key' | 'Sec-Websocket-Protocol' | 'Sec-Websocket-Version' | 'Strict-Transport-Security' | 'Tk' | 'Trailer' | 'Transfer-Encoding' | 'Upgrade' | 'User-Agent' | 'Vary' | 'Via' | 'Warning' | 'WWW-Authenticate'; | ||
}; | ||
get path(): string; | ||
protected _parsedUrl: URL | null; | ||
get pathname(): string; | ||
/** | ||
* Get the search string. Same as the query string | ||
* except it includes the leading `?` | ||
*/ | ||
get search(): string; | ||
get querystring(): string; | ||
@@ -166,2 +172,8 @@ get query(): Record<string, unknown>; | ||
get ip(): string; | ||
/** | ||
* Get full request URL, include protocol, host and url | ||
*/ | ||
get href(): string; | ||
get origin(): string; | ||
get host(): string; | ||
get protocol(): string; | ||
@@ -176,2 +188,3 @@ get secure(): boolean; | ||
}; | ||
protected get URL(): URL; | ||
} | ||
@@ -178,0 +191,0 @@ declare module 'node:http' { |
@@ -26,3 +26,3 @@ // src/override/middleware.ts | ||
if (options.path) { | ||
const { path: pathname } = ctx.request; | ||
const { pathname } = ctx.request; | ||
return toArray(options.path).some( | ||
@@ -33,3 +33,3 @@ (path) => typeof path === "string" ? path === pathname : path.exec(pathname) !== null | ||
if (options.ext) { | ||
const currentExt = extname(ctx.request.path); | ||
const currentExt = extname(ctx.request.pathname); | ||
if (currentExt === "") | ||
@@ -164,3 +164,2 @@ return false; | ||
import { IncomingMessage } from "node:http"; | ||
import parseurl from "parseurl"; | ||
import qs from "qs"; | ||
@@ -184,13 +183,18 @@ import cookie from "cookie"; | ||
_cookie; | ||
get path() { | ||
return parseurl(this).pathname; | ||
_parsedUrl = null; | ||
get pathname() { | ||
return this.URL.pathname; | ||
} | ||
/** | ||
* Get the search string. Same as the query string | ||
* except it includes the leading `?` | ||
*/ | ||
get search() { | ||
return this.URL.search; | ||
} | ||
get querystring() { | ||
return parseurl(this).query; | ||
return this.URL.search.slice(1); | ||
} | ||
get query() { | ||
return this._query ||= qs.parse(this.querystring, { | ||
comma: true, | ||
...this.app.options.query | ||
}); | ||
return this._query ||= qs.parse(this.querystring, this.app.options.query); | ||
} | ||
@@ -239,2 +243,21 @@ get body() { | ||
} | ||
/** | ||
* Get full request URL, include protocol, host and url | ||
*/ | ||
get href() { | ||
return this.origin + this.url; | ||
} | ||
get origin() { | ||
return `${this.protocol}://${this.host}`; | ||
} | ||
get host() { | ||
let host = this.headers["x-forwarded-host"]; | ||
if (!host) { | ||
if (this.httpVersionMajor >= 2) { | ||
host = this.headers[":authority"]; | ||
} | ||
host ||= this.headers["host"]; | ||
} | ||
return host && host.split(/\s*,\s*/, 1)[0] || ""; | ||
} | ||
get protocol() { | ||
@@ -269,2 +292,5 @@ if (this.socket.encrypted) | ||
} | ||
get URL() { | ||
return this._parsedUrl ||= new URL(this.href); | ||
} | ||
}; | ||
@@ -279,2 +305,3 @@ | ||
import encodeUrl from "encodeurl"; | ||
import contentType2 from "content-type"; | ||
import destroy from "destroy"; | ||
@@ -288,11 +315,11 @@ import contentDisposition from "content-disposition"; | ||
import mimeTypes2 from "mime-types"; | ||
import LRU from "lru-cache"; | ||
var cache = new LRU({ | ||
max: 100 | ||
import { MemoryCache } from "@aomex/core"; | ||
var cache = new MemoryCache({ | ||
maxItems: 100 | ||
}); | ||
var getMimeType = (filenameOrExt) => { | ||
let mimeType = cache.get(filenameOrExt); | ||
let mimeType = cache.lru.get(filenameOrExt); | ||
if (!mimeType) { | ||
mimeType = mimeTypes2.contentType(filenameOrExt); | ||
cache.set(filenameOrExt, mimeType); | ||
cache.lru.set(filenameOrExt, mimeType); | ||
} | ||
@@ -380,10 +407,12 @@ return mimeType; | ||
get contentType() { | ||
let type = this.getHeader("Content-Type"); | ||
type &&= type.split(";", 1)[0]; | ||
return type || ""; | ||
return this.hasHeader("Content-Type") ? contentType2.parse(this).type : ""; | ||
} | ||
set contentType(typeOrFilenameOrExt) { | ||
const mimeType = getMimeType(typeOrFilenameOrExt); | ||
if (mimeType === false) { | ||
throw new Error(`\u65E0\u6CD5\u6839\u636E\u53C2\u6570"${typeOrFilenameOrExt}"\u8BBE\u7F6EContent-Type`); | ||
try { | ||
if (mimeType === false) | ||
throw new Error(); | ||
contentType2.parse(mimeType); | ||
} catch { | ||
throw new TypeError(`invalid content-type: '${typeOrFilenameOrExt}'`); | ||
} | ||
@@ -733,3 +762,3 @@ this.setHeader("Content-Type", mimeType); | ||
statusCode, | ||
contentType: contentType2 = "*/*", | ||
contentType: contentType3 = "*/*", | ||
schema, | ||
@@ -743,3 +772,3 @@ headers = {}, | ||
content: { | ||
[this.fixContentType(contentType2)]: { | ||
[this.fixContentType(contentType3)]: { | ||
schema: Validator5.toDocument( | ||
@@ -759,4 +788,4 @@ schema instanceof Validator5 ? schema : rule2.object(schema) | ||
} | ||
fixContentType(contentType2) { | ||
const type = contentType2.includes("*") ? contentType2 : getMimeType(contentType2) || "*/*"; | ||
fixContentType(contentType3) { | ||
const type = contentType3.includes("*") ? contentType3 : getMimeType(contentType3) || "*/*"; | ||
return type.split(";", 1)[0]; | ||
@@ -763,0 +792,0 @@ } |
{ | ||
"name": "@aomex/web", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"description": "", | ||
@@ -29,3 +29,3 @@ "type": "module", | ||
"peerDependencies": { | ||
"@aomex/core": "^0.0.10" | ||
"@aomex/core": "^0.0.11" | ||
}, | ||
@@ -52,6 +52,4 @@ "dependencies": { | ||
"http-errors": "^2.0.0", | ||
"lru-cache": "^7.17.0", | ||
"mime-types": "^2.1.35", | ||
"parseurl": "^1.3.3", | ||
"qs": "^6.11.0", | ||
"qs": "^6.11.1", | ||
"request-ip": "^3.3.0", | ||
@@ -63,3 +61,3 @@ "statuses": "^2.0.1", | ||
"devDependencies": { | ||
"@aomex/core": "^0.0.10", | ||
"@aomex/core": "^0.0.11", | ||
"@types/co-body": "^6.1.0", | ||
@@ -72,3 +70,2 @@ "@types/content-type": "^1.1.5", | ||
"@types/mime-types": "^2.1.1", | ||
"@types/parseurl": "^1.3.1", | ||
"@types/request-ip": "^0.0.37", | ||
@@ -75,0 +72,0 @@ "@types/type-is": "^1.6.3", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
97344
26
11
1215
+ Added@aomex/cache@0.0.6(transitive)
+ Added@aomex/core@0.0.11(transitive)
+ Added@aomex/validator@0.0.10(transitive)
+ Addedlru-cache@8.0.5(transitive)
- Removedlru-cache@^7.17.0
- Removedparseurl@^1.3.3
- Removed@aomex/cache@0.0.5(transitive)
- Removed@aomex/core@0.0.10(transitive)
- Removed@aomex/validator@0.0.9(transitive)
- Removedlru-cache@7.18.3(transitive)
- Removedparseurl@1.3.3(transitive)
Updatedqs@^6.11.1