-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (29 loc) · 947 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
let symbols = require("./symbols.js")
let serve = require("./library/serve.js")
let route = require("./route.js")
let checkFileExists = require("./library/check-file-existence.js")
let websiteDirectory = "website"
module.exports = async (request, response) => {
let boop = await route(request, response)
if (boop.type == symbols.module) {
return boop.result
}
if (boop.type == symbols.redirect) {
response.statusCode = 302
response.setHeader("Location", boop.to)
response.end()
return
}
if (boop.type == symbols.static) {
return serve(boop)
}
if (boop.type == symbols.nothing) {
let websiteExists = await checkFileExists(websiteDirectory)
return websiteExists
? serve({request, response, websiteDirectory})
: new Error(
`i couldnt boop such a snoot and your website directory (${websiteDirectory}) did not exist`
)
}
return new Error(`i refuse to apply to a snoot a boop of a type i don't know`)
}