Repository URL to install this package:
|
Version:
1.2.7 ▾
|
const { oneRouter } = require('@skava/modules/___dist/router')
function initOneUrl() {
const protocol = process.env.HTTPS ? 'https' : 'http'
const host = process.env.HOST
global.oneUrl = {
protocol,
host,
pathname: '/',
search: {},
hash: '',
full: `${protocol}://${host}/`,
userAgent: '',
}
oneRouter.urlFromExpress = global.oneUrl
}
// avoid Error: could not find pathname
initOneUrl()
function routingMiddleware(req, res, next) {
const hostess = req.get('host')
const {
headers,
protocol,
originalUrl,
pathname,
hash,
search = {},
params = {},
query = {},
} = req
const searchParams = { ...search, ...params, ...query }
// @todo @fixme - one spreads array or string
if (searchParams['0']) {
delete searchParams['0']
}
/* eslint prefer-template: "error" */
function fromScatterBrainedPiecesIntoNormalStandardAddress(argsWouldGoHere) {
req.oneUrl = {
protocol,
host: hostess,
pathname: pathname || originalUrl,
hash,
search: searchParams,
// not in rr
full: `${protocol}://${hostess}${originalUrl}`,
userAgent: headers['user-agent'],
}
if (
req.oneUrl.pathname &&
req.oneUrl.pathname.includes('_webpack') === false
) {
global.oneUrl = req.oneUrl
}
console.log('[oneRouter] EXPRESSURL', req.oneUrl)
}
// const requestCookie = req.Cookie || req.cookie || req.headers.cookie || req.headers.Cookie
// console.log(requestCookie)
fromScatterBrainedPiecesIntoNormalStandardAddress()
next()
}
export { routingMiddleware }