Skip to content

Commit

Permalink
Temporary: Add Support for Now Platform Headers (#9085)
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer authored Oct 15, 2019
1 parent 8676b0f commit c77338b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/next/build/webpack/loaders/next-serverless-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,17 @@ const nextServerlessLoader: loader.Loader = function() {
? `const params = fromExport && !unstable_getStaticProps ? {} : getRouteMatcher(getRouteRegex("${page}"))(parsedUrl.pathname) || {};`
: `const params = {};`
}
const result = await renderToHTML(req, res, "${page}", Object.assign({}, unstable_getStaticProps ? {} : parsedUrl.query, params, sprData ? { _nextSprData: '1' } : {}), renderOpts)
${
// Temporary work around -- `x-now-route-params` is a platform header
// _only_ set for `Prerender` requests. We should move this logic
// into our builder to ensure we're decoupled. However, this entails
// removing reliance on `req.url` and using `req.query` instead
// (which is needed for "custom routes" anyway).
isDynamicRoute(page)
? `const nowParams = (req.headers && req.headers["x-now-route-params"]) ? querystring.parse(req.headers["x-now-route-params"]) : null;`
: `const nowParams = null;`
}
const result = await renderToHTML(req, res, "${page}", Object.assign({}, unstable_getStaticProps ? {} : parsedUrl.query, nowParams ? nowParams : params, sprData ? { _nextSprData: '1' } : {}), renderOpts)
if (fromExport) return { html: result, renderOpts }
return result
Expand Down

0 comments on commit c77338b

Please sign in to comment.