Commit 53cb590c authored by Matthew Gall's avatar Matthew Gall

Added product identification by subdomain

parent 4e2b9d56
......@@ -11,9 +11,24 @@ function isInArray(value, array) {
* @param {Request} request
*/
async function handleRequest(request) {
path = new URL(request.url).pathname;
return new Response('Welcome to mirror.wales', {
const PRODUCT_NAME = "mirror.wales"
let host = new URL(request.url).host
let path = new URL(request.url).pathname;
// Now we do some syntax checking to ensure the host is valid
if (host.includes(`.${PRODUCT_NAME}`) == false) {
return new Response(`You requested an invalid host. Please visit our website at ${PRODUCT_NAME}`, {
headers: {
'Content-Type': 'text/plain'
}
})
}
// Now we fetch the subdomain from the host
let product = host.replace(`.${PRODUCT_NAME}`, '')
return new Response(product, {
headers: {
'Content-Type': 'text/plain'
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment