-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
117 lines (107 loc) · 3.71 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { initializeApp } from "./functions/initialize.js"
import { staticAssetLoader } from "./functions/static-asset-loader.js"
import { createServer } from "./functions/router.js"
import { drive } from "./functions/deta-drive.js"
import { getSettings } from "./functions/settings.js"
// Initialize application
const { app, eta } = initializeApp()
// Set the port value
const port = process.env.PORT || 8080
// Load static assets from `static` folder in Blog-Doc App
staticAssetLoader.serveStaticAssets(app)
// Load static assets from Blog-Doc Drive
import { staticAssetRoute } from "./routes/staticAssetRoute.js"
staticAssetRoute(app)
// Entry Route Depending On Drive's Content
import { mainRoute } from "./routes/mainRoute.js"
import { adminBlogDocConfigRoute } from "./routes/admin/adminBlogDocConfigRoute.js"
async function entryRoute() {
let allFiles = (await drive.list()).names.length
if (allFiles == 0) {
adminBlogDocConfigRoute(app)
} else {
mainRoute(app)
}
}
await entryRoute()
// Administration Routes
import { adminRoutes, adminUpdateDelete } from "./routes/admin/adminRoute.js"
import { adminCreateRoute } from "./routes/admin/adminCreateRoute.js"
import { adminGalleryRoute } from "./routes/admin/adminGalleryRoute.js"
import { adminConfigRoute } from "./routes/admin/adminConfigRoute.js"
import { adminPreviewRoute } from "./routes/admin/adminPreviewRoute.js"
adminRoutes(app)
adminCreateRoute(app)
adminUpdateDelete(app)
adminGalleryRoute(app)
adminConfigRoute(app)
adminPreviewRoute(app)
// Routes
import { markdownRoute } from "./routes/markdownRoute.js"
import { archiveRoute } from "./routes/archiveRoute.js"
import { searchRoute } from "./routes/searchRoute.js"
import { tagsRoute } from "./routes/tagsRoute.js"
import { rssRoute } from "./routes/rssRoute.js"
import { sitemapRoute } from "./routes/sitemapRoute.js"
markdownRoute(app)
archiveRoute(app)
searchRoute(app)
tagsRoute(app)
rssRoute(app)
sitemapRoute(app)
// 404 Route
app.notFound(async (req, res) => {
const settings = await getSettings()
const data = {
title: "Page Not Found",
description: "The server cannot find the requested resource",
subTitle: "Nothing to land on here !",
favicon: settings.favicon,
}
const response = eta.render(`themes/${settings.currentTheme}/layouts/base.html`, {
// Passing Route data
errorRoute: true,
// Passing document data
data: data,
// Passing document image data
imageSrc: "/static/images/404-not-found-error.png",
imageAlt: "Sailor on a 404 mast looking out to sea",
// Passing needed settings for the template
siteTitle: settings.siteTitle,
menuLinks: settings.menuLinks,
footerCopyright: settings.footerCopyright,
})
res.writeHead(404, { "Content-Type": "text/html" })
res.end(response)
return
})
// 500 Route
app.onError(async (error, req, res) => {
console.error("Something went wrong:", error)
const settings = await getSettings()
const data = {
title: "Internal Server Error",
description: "The server encountered an unexpected condition that prevented it from fulfilling the request",
subTitle: "Server is on a break here !",
favicon: settings.favicon,
}
const response = eta.render(`themes/${settings.currentTheme}/layouts/base.html`, {
// Passing Route data
errorRoute: true,
// Passing document data
data: data,
// Passing document image data
imageSrc: "/static/images/500-internal-server-error.png",
imageAlt: "Sad robot in front of empty box",
// Passing needed settings for the template
siteTitle: settings.siteTitle,
menuLinks: settings.menuLinks,
footerCopyright: settings.footerCopyright,
})
res.writeHead(500, { "Content-Type": "text/html" })
res.end(response)
return
})
createServer(app).listen(port, () => {
console.log(`App @ http://localhost:${port}`)
})