@kaliber/build 0.0.153 → 0.0.155
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/serve.js +11 -4
- package/package.json +1 -1
package/lib/serve.js
CHANGED
@@ -69,7 +69,7 @@ app.use((err, req, res, next) => {
|
|
69
69
|
return res.status(err.status).send()
|
70
70
|
|
71
71
|
reportServerError(err, req)
|
72
|
-
serveInternalServerError(err,
|
72
|
+
serveInternalServerError(err, req, res, next)
|
73
73
|
})
|
74
74
|
|
75
75
|
app.listen(port, () => console.log(`Server listening at port ${port}`))
|
@@ -88,7 +88,9 @@ async function resolveFile(req, res, next) {
|
|
88
88
|
for (const dir of dirs) {
|
89
89
|
for (const [file, handler] of combinations) {
|
90
90
|
const filePath = resolve(dir, file)
|
91
|
-
if (await fileExists(filePath))
|
91
|
+
if (await fileExists(filePath)) {
|
92
|
+
return handler(filePath)
|
93
|
+
}
|
92
94
|
}
|
93
95
|
}
|
94
96
|
|
@@ -135,9 +137,14 @@ function possibleDirectories(path) {
|
|
135
137
|
|
136
138
|
function serveIndexWithRouting(file, req, res, next) {
|
137
139
|
const routeTemplate = envRequire(file)
|
138
|
-
|
139
140
|
const location = parsePath(req.url)
|
140
141
|
|
142
|
+
if (routeTemplate.handleRequest)
|
143
|
+
return routeTemplate.handleRequest(location, req, res).catch(error => {
|
144
|
+
reportServerError(error, req)
|
145
|
+
serveInternalServerError(error, req, res, next)
|
146
|
+
})
|
147
|
+
|
141
148
|
const [dataOrPromise, template] = getDataAndRouteTemplate(routeTemplate, location, req)
|
142
149
|
|
143
150
|
if (dataOrPromise.then)
|
@@ -178,7 +185,7 @@ function getDataAndRouteTemplate(routeTemplate, location, req) {
|
|
178
185
|
return [dataOrPromise, envRequire(indexPath)]
|
179
186
|
}
|
180
187
|
|
181
|
-
function serveInternalServerError(error,
|
188
|
+
function serveInternalServerError(error, req, res, next) {
|
182
189
|
const response = res.status(500)
|
183
190
|
if (isProduction) {
|
184
191
|
findFile(req.path, internalServerError)
|
package/package.json
CHANGED