Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in / Register
Toggle navigation
M
mirror.wales
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
PiCymru
mirror.wales
Commits
3ff74dca
Commit
3ff74dca
authored
Nov 11, 2018
by
Matthew Gall
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added configuration view from worker.js
parent
53cb590c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
3 deletions
+24
-3
worker.js
worker.js
+24
-3
No files found.
worker.js
View file @
3ff74dca
...
...
@@ -18,7 +18,7 @@ async function handleRequest(request) {
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
)
{
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
'
...
...
@@ -26,9 +26,30 @@ async function handleRequest(request) {
})
}
// Now we fetch the subdomain from the host
// Now, for the main website
if
(
host
==
PRODUCT_NAME
)
{
return
new
Response
(
`Welcome to mirror.wales`
,
{
headers
:
{
'
Content-Type
'
:
'
text/plain
'
}
})
}
// Now we fetch the subdomain from the host, if it's a subdomain
let
product
=
host
.
replace
(
`.
${
PRODUCT_NAME
}
`
,
''
)
return
new
Response
(
product
,
{
// And load the configuration so we can find out how to handle the request
let
config
=
await
mirrors
.
get
(
'
mirrors
'
)
if
(
config
===
null
)
{
return
new
Response
(
`We are unable to handle your request at present due to a configuration issue. Please try again later`
,
{
headers
:
{
'
Content-Type
'
:
'
text/plain
'
}
})
}
config
=
JSON
.
parse
(
config
)
return
new
Response
(
config
[
product
],
{
headers
:
{
'
Content-Type
'
:
'
text/plain
'
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment