fetch-metadata
Advanced tools
Comparing version 0.1.0 to 0.2.1
@@ -22,3 +22,8 @@ 'use strict'; | ||
allowedPaths: [], | ||
errorStatusCode: 403 | ||
errorStatusCode: 403, | ||
// @ts-expect-error | ||
onError: function onError(req, res, next, options) { | ||
res.statusCode = options.errorStatusCode; | ||
res.end(); | ||
} | ||
}; | ||
@@ -61,4 +66,3 @@ | ||
res.statusCode = options.errorStatusCode; | ||
res.end(); | ||
options.onError(req, res, next, options); | ||
}; | ||
@@ -65,0 +69,0 @@ } |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=function(e,t){var s=e.headers[t];return Array.isArray(s)?s.join(","):s||""},t={allowedFetchSites:["same-origin","same-site","none"],disallowedNavigationRequests:["object","embed"],allowedPaths:[],errorStatusCode:403};function s(s){void 0===s&&(s={});var r=Object.assign(t,s);return function(t,s,a){var o,i=function(t){return{secFetchSite:e(t,"sec-fetch-site"),secFetchMode:e(t,"sec-fetch-mode"),secFetchDest:e(t,"sec-fetch-dest")}}(t),d=i.secFetchSite,c=i.secFetchMode,l=i.secFetchDest;return d?Array.isArray(r.allowedFetchSites)&&r.allowedFetchSites.includes(d)||"navigate"===c&&"GET"===(null===(o=t.method)||void 0===o?void 0:o.toUpperCase())&&Array.isArray(r.disallowedNavigationRequests)&&!r.disallowedNavigationRequests.includes(l)||Array.isArray(r.allowedPaths)&&r.allowedPaths.includes(t.url||"")?a():(s.statusCode=r.errorStatusCode,void s.end()):a()}}module.exports=s,exports.default=s; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=function(e,t){var s=e.headers[t];return Array.isArray(s)?s.join(","):s||""},t={allowedFetchSites:["same-origin","same-site","none"],disallowedNavigationRequests:["object","embed"],allowedPaths:[],errorStatusCode:403,onError:function(e,t,s,r){t.statusCode=r.errorStatusCode,t.end()}};function s(s){void 0===s&&(s={});var r=Object.assign(t,s);return function(t,s,o){var a,i=function(t){return{secFetchSite:e(t,"sec-fetch-site"),secFetchMode:e(t,"sec-fetch-mode"),secFetchDest:e(t,"sec-fetch-dest")}}(t),d=i.secFetchSite,c=i.secFetchMode,n=i.secFetchDest;return d?Array.isArray(r.allowedFetchSites)&&r.allowedFetchSites.includes(d)||"navigate"===c&&"GET"===(null===(a=t.method)||void 0===a?void 0:a.toUpperCase())&&Array.isArray(r.disallowedNavigationRequests)&&!r.disallowedNavigationRequests.includes(n)||Array.isArray(r.allowedPaths)&&r.allowedPaths.includes(t.url||"")?o():void r.onError(t,s,o,r):o()}}module.exports=s,exports.default=s; | ||
//# sourceMappingURL=fetch-metadata.cjs.production.min.js.map |
@@ -18,3 +18,8 @@ var extractHeader = function extractHeader(req, header) { | ||
allowedPaths: [], | ||
errorStatusCode: 403 | ||
errorStatusCode: 403, | ||
// @ts-expect-error | ||
onError: function onError(req, res, next, options) { | ||
res.statusCode = options.errorStatusCode; | ||
res.end(); | ||
} | ||
}; | ||
@@ -57,4 +62,3 @@ | ||
res.statusCode = options.errorStatusCode; | ||
res.end(); | ||
options.onError(req, res, next, options); | ||
}; | ||
@@ -61,0 +65,0 @@ } |
@@ -0,2 +1,4 @@ | ||
/// <reference types="node" /> | ||
import { IncomingMessage, ServerResponse } from 'http'; | ||
declare type Next = (error?: Error) => void; | ||
declare type Config = { | ||
@@ -7,4 +9,5 @@ allowedFetchSites: string[]; | ||
errorStatusCode: number; | ||
onError: (request: IncomingMessage, response: ServerResponse, next: Next, options: Config) => void; | ||
}; | ||
declare function middlewareWrapper(config?: Partial<Config>): (req: IncomingMessage, res: ServerResponse, next: () => void) => void; | ||
declare function middlewareWrapper(config?: Partial<Config>): (req: IncomingMessage, res: ServerResponse, next: Next) => void; | ||
export default middlewareWrapper; |
{ | ||
"version": "0.1.0", | ||
"version": "0.2.1", | ||
"license": "MIT", | ||
@@ -13,2 +13,9 @@ "main": "dist/index.js", | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:jperasmus/fetch-metadata.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/jperasmus/fetch-metadata/issues" | ||
}, | ||
"keywords": [ | ||
@@ -15,0 +22,0 @@ "node.js", |
@@ -32,2 +32,7 @@ # Fetch Metadata Request Headers Middleware | ||
errorStatusCode: 403, | ||
onError: (request, response, next, options) => { | ||
// Responds with `errorStatusCode` by default | ||
response.statusCode = options.errorStatusCode | ||
response.end() | ||
}, | ||
}) | ||
@@ -34,0 +39,0 @@ ) |
@@ -16,2 +16,4 @@ import { IncomingMessage, ServerResponse } from 'http' | ||
type Next = (error?: Error) => void | ||
type Config = { | ||
@@ -22,2 +24,8 @@ allowedFetchSites: string[] | ||
errorStatusCode: number | ||
onError: ( | ||
request: IncomingMessage, | ||
response: ServerResponse, | ||
next: Next, | ||
options: Config | ||
) => void | ||
} | ||
@@ -30,2 +38,7 @@ | ||
errorStatusCode: 403, | ||
// @ts-expect-error | ||
onError: (req, res, next, options) => { | ||
res.statusCode = options.errorStatusCode | ||
res.end() | ||
}, | ||
} | ||
@@ -39,3 +52,3 @@ | ||
res: ServerResponse, | ||
next: () => void | ||
next: Next | ||
) { | ||
@@ -76,4 +89,3 @@ const { secFetchSite, secFetchMode, secFetchDest } = getSecFetchHeaders(req) | ||
res.statusCode = options.errorStatusCode | ||
res.end() | ||
options.onError(req, res, next, options) | ||
} | ||
@@ -80,0 +92,0 @@ } |
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
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
26156
206
0
44
1