Add Domain middleware
This commit is contained in:
parent
7e8891f706
commit
3645dc5c5f
1 changed files with 15 additions and 0 deletions
15
utils/middleware/domain.ts
Normal file
15
utils/middleware/domain.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import { pogo } from "../../deps.ts"
|
||||||
|
interface RequestParameters { r: pogo.Request, h: pogo.Toolkit }
|
||||||
|
|
||||||
|
export default ({ r, h }: RequestParameters, domains: string[] | string, handler: any) => {
|
||||||
|
if (domains.includes(r.host) || domains.includes("*")) {
|
||||||
|
console.log("Call actual Handler")
|
||||||
|
return handler(r, h)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
console.log("Throw Error")
|
||||||
|
return h.response({
|
||||||
|
error: "This Site/Fuction doesn't exist or is not available on the current domain."
|
||||||
|
}).code(404)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue