micro-switch-router
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "micro-switch-router", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "", | ||
@@ -12,5 +12,12 @@ "main": "src", | ||
"devDependencies": { | ||
"jest": "^23.4.0" | ||
"axios": "^0.18.0", | ||
"jest": "^23.4.0", | ||
"lodash": "^4.17.10", | ||
"test-listen": "^1.1.0" | ||
}, | ||
"dependencies": {} | ||
"dependencies": { | ||
"micro": "^9.3.2", | ||
"query-string": "^6.1.0", | ||
"react-router": "^4.3.1" | ||
} | ||
} |
const { json } = require('micro') | ||
const qs = require('query-string') | ||
const url = require('url') | ||
const { isDev } = require('../utils/environment') | ||
const enhanceReq = async (req) => { | ||
const parsedUrl = url.parse(req.url) | ||
req.protocol = isDev ? 'http:' : 'https:' | ||
req.originalUrl = `${req.protocol}${req.headers.host}${req.url}` | ||
req.protocol = process.env.NODE_ENV === 'production' ? 'https:' : 'http:' | ||
req.hostname = req.headers.host.split(':')[0] // Remove port # to get hostname | ||
req.port = req.headers.host.split(':')[1] // Remove port # to get hostname | ||
req.pathname = parsedUrl.pathname | ||
/** | ||
* req.headers.host is where the request is pointed | ||
*/ | ||
req.search = parsedUrl.search | ||
req.href = parsedUrl.href | ||
req.query = qs.parse(parsedUrl.query) | ||
req.originalUrl = url.format({ | ||
protocol: req.protocol, | ||
hostname: req.hostname, | ||
pathname: req.pathname, | ||
query: req.query, | ||
}); | ||
req.host = req.headers.host | ||
req.hostname = req.headers.host.split(':')[0] // Remove port # to get hostname | ||
req.body = await json(req).catch(Boolean) | ||
req.query = qs.parse(parsedUrl.query) | ||
} | ||
module.exports = enhanceReq |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
117985
9
139
3
4
2
+ Addedmicro@^9.3.2
+ Addedquery-string@^6.1.0
+ Addedreact-router@^4.3.1
+ Added@babel/runtime@7.25.6(transitive)
+ Addedarg@4.1.0(transitive)
+ Addedbytes@3.1.0(transitive)
+ Addedcontent-type@1.0.4(transitive)
+ Addeddecode-uri-component@0.2.2(transitive)
+ Addeddepd@1.1.2(transitive)
+ Addedfilter-obj@1.1.0(transitive)
+ Addedhistory@4.10.1(transitive)
+ Addedhoist-non-react-statics@2.5.5(transitive)
+ Addedhttp-errors@1.7.3(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedinvariant@2.2.4(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedloose-envify@1.4.0(transitive)
+ Addedmicro@9.4.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedpath-to-regexp@1.9.0(transitive)
+ Addedprop-types@15.8.1(transitive)
+ Addedquery-string@6.14.1(transitive)
+ Addedraw-body@2.4.1(transitive)
+ Addedreact@18.3.1(transitive)
+ Addedreact-is@16.13.1(transitive)
+ Addedreact-router@4.3.1(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)
+ Addedresolve-pathname@3.0.0(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsetprototypeof@1.1.1(transitive)
+ Addedsplit-on-first@1.1.0(transitive)
+ Addedstatuses@1.5.0(transitive)
+ Addedstrict-uri-encode@2.0.0(transitive)
+ Addedtiny-invariant@1.3.3(transitive)
+ Addedtiny-warning@1.0.3(transitive)
+ Addedtoidentifier@1.0.0(transitive)
+ Addedunpipe@1.0.0(transitive)
+ Addedvalue-equal@1.0.1(transitive)
+ Addedwarning@4.0.3(transitive)