Skip to content

Commit c69faab

Browse files
committed
feat: 404.html and 403.html fetched from orgs files, with default fallbacks handeled by platform
1 parent 04a6f15 commit c69faab

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/index.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const organizations = new Map();
1111

1212
class CoCreateFileSystem {
1313
constructor(crud, render) {
14-
let default404, default403
1514

1615
async function defaultFiles(fileName) {
1716
let file = await crud.readDocument({
@@ -25,12 +24,19 @@ class CoCreateFileSystem {
2524
})
2625
if (!file || !file.document || !file.document[0])
2726
return ''
28-
return file.document[0]
27+
return file.document[0].src
2928
}
3029

31-
// const default404 = defaultFiles('/404.html')
32-
// const default403 = defaultFiles('/403.html')
33-
console.log('defualtfiles', default404, default403)
30+
let default403, default404, hostNotFound
31+
defaultFiles('/403.html').then((file) => {
32+
default403 = file
33+
})
34+
defaultFiles('/404.html').then((file) => {
35+
default404 = file
36+
})
37+
defaultFiles('/hostNotFound.html').then((file) => {
38+
hostNotFound = file
39+
})
3440

3541
this.router = router.get('/*', async(req, res) => {
3642
let hostname = req.hostname;
@@ -47,8 +53,7 @@ class CoCreateFileSystem {
4753
})
4854

4955
if (!organization || !organization.document || !organization.document[0]) {
50-
// ToDo: get response from platform.db.file.hostNotFound
51-
let hostNotFound = 'Organization cannot be found using the host: ' + hostname + ' in platformDB: ' + process.env.organization_id
56+
hostNotFound = hostNotFound || 'Organization cannot be found using the host: ' + hostname + ' in platformDB: ' + process.env.organization_id
5257
return res.send(hostNotFound);
5358
}
5459

@@ -90,7 +95,9 @@ class CoCreateFileSystem {
9095

9196
let pageNotFound = await crud.readDocument(data);
9297
if (!pageNotFound || !pageNotFound.document || !pageNotFound.document[0])
93-
pageNotFound = `${url} could not be found for ${organization_id}`
98+
pageNotFound = default404 || `${url} could not be found for ${organization_id}`
99+
else
100+
pageNotFound = pageNotFound.document[0].src
94101
return res.status(404).send(pageNotFound);
95102
}
96103

@@ -102,7 +109,10 @@ class CoCreateFileSystem {
102109

103110
let pageForbidden = await crud.readDocument(data);
104111
if (!pageForbidden || !pageForbidden.document || !pageForbidden.document[0])
105-
pageForbidden = `${url} access not allowed for ${organization_id}`
112+
pageForbidden = default403 || `${url} access not allowed for ${organization_id}`
113+
else
114+
pageForbidden = pageForbidden.document[0].src
115+
106116
return res.status(403).send(pageForbidden);
107117
}
108118

0 commit comments

Comments
 (0)