2021-08-05 10:59:08 +02:00
|
|
|
const { setTenantId } = require("../tenancy")
|
|
|
|
const ContextFactory = require("../tenancy/FunctionContext")
|
|
|
|
const { buildMatcherRegex, matches } = require("./matchers")
|
|
|
|
|
2021-09-06 17:01:45 +02:00
|
|
|
module.exports = (
|
|
|
|
allowQueryStringPatterns,
|
|
|
|
noTenancyPatterns,
|
2021-09-06 17:18:50 +02:00
|
|
|
opts = {}
|
2021-09-06 17:01:45 +02:00
|
|
|
) => {
|
2021-08-05 10:59:08 +02:00
|
|
|
const allowQsOptions = buildMatcherRegex(allowQueryStringPatterns)
|
|
|
|
const noTenancyOptions = buildMatcherRegex(noTenancyPatterns)
|
|
|
|
|
|
|
|
return ContextFactory.getMiddleware(ctx => {
|
2021-09-06 17:18:50 +02:00
|
|
|
const allowNoTenant = opts.noTenancyRequired || !!matches(ctx, noTenancyOptions)
|
2021-08-05 10:59:08 +02:00
|
|
|
const allowQs = !!matches(ctx, allowQsOptions)
|
|
|
|
setTenantId(ctx, { allowQs, allowNoTenant })
|
|
|
|
})
|
|
|
|
}
|