@kaliber/build 0.0.141 → 0.0.142

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/lib/serve.js +12 -3
  2. package/package.json +1 -1
package/lib/serve.js CHANGED
@@ -140,14 +140,23 @@ function possibleDirectories(path) {
140
140
 
141
141
  function serveIndexWithRouting(req, res, file) {
142
142
  const envRequire = isProduction ? require : require('import-fresh')
143
- const template = envRequire(file)
143
+ const routeTemplate = envRequire(file)
144
144
 
145
- const routes = template.routes
145
+ const routes = routeTemplate.routes
146
146
  const location = parsePath(req.url)
147
147
 
148
148
  return Promise.resolve(routes)
149
149
  .then(routes => (routes && routes.match(location, req)) || { status: 200, data: null })
150
- .then(({ status, headers, data }) =>
150
+ .then(data => {
151
+ if (!routes || !routes.resolveIndex) return [data, routeTemplate]
152
+
153
+ const indexLocation = routes.resolveIndex(location, req)
154
+ if (!indexLocation) return [data, routeTemplate]
155
+
156
+ const indexPath = resolve(target, publicPathDir, indexLocation, indexWithRouting)
157
+ return [data, envRequire(indexPath)]
158
+ })
159
+ .then(([{ status, headers, data }, template]) =>
151
160
  Promise.resolve(template({ location, data })).then(html => [status, headers, html])
152
161
  )
153
162
  .then(([ status, headers, html ]) => res.status(status).set(headers).send(html))
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.141",
2
+ "version": "0.0.142",
3
3
  "name": "@kaliber/build",
4
4
  "description": "Zero configuration, opinionated webpack / react build setup",
5
5
  "scripts": {