|
1 | 1 | // TEMPLATE: This file will be copied to the Netlify functions directory when
|
2 |
| -// running next-on-netlify/run.js |
| 2 | +// running next-on-netlify |
3 | 3 |
|
4 |
| -const compat = require("next-aws-lambda") |
5 |
| -const { routes } = require("./routes.json") |
| 4 | +// Compatibility wrapper for NextJS page |
| 5 | +const compat = require("next-aws-lambda") |
| 6 | +// Load the NextJS page |
| 7 | +const page = require("./nextJsPage") |
6 | 8 |
|
7 |
| -// We have to require all pages here so that Netlify's zip-it-and-ship-it |
8 |
| -// method will bundle them. That makes them available for our dynamic require |
9 |
| -// statement later. |
10 |
| -// We wrap this require in if(false) to make sure it is *not* executed when the |
11 |
| -// function runs. |
12 |
| -if (false) { |
13 |
| - require("./allPages") |
14 |
| -} |
15 |
| - |
16 |
| -// Look through all routes and check each regex against the request URL |
17 |
| -const getRoute = path => { |
18 |
| - route = routes.find(({ regex }) => { |
19 |
| - const re = new RegExp(regex, "i"); |
20 |
| - return re.test(path); |
21 |
| - }) |
22 |
| - |
23 |
| - // Return the route or the error page |
24 |
| - return route || { file: "pages/_error.js" } |
25 |
| -} |
26 |
| - |
27 |
| -// There are some minor differences between Netlify and AWS, such as AWS having |
28 |
| -// support for multi-value headers. |
29 |
| -// next-aws-lambda is made for AWS, so we need to resolve those differences to |
30 |
| -// make everything work with Netlify. |
| 9 | +// next-aws-lambda is made for AWS. There are some minor differences between |
| 10 | +// Netlify and AWS which we resolve here. |
31 | 11 | const callbackHandler = callback => (
|
32 | 12 | // The callbackHandler wraps the callback
|
33 | 13 | (argument, response) => {
|
@@ -57,17 +37,6 @@ exports.handler = (event, context, callback) => {
|
57 | 37 | const { path } = event
|
58 | 38 | console.log("[request]", path)
|
59 | 39 |
|
60 |
| - // Identify the file to render |
61 |
| - const { file } = getRoute(path) |
62 |
| - console.log("[render] ", file) |
63 |
| - |
64 |
| - // Load the page to render |
65 |
| - // Do not do this: const page = require(`./${file}`) |
66 |
| - // Otherwise, Netlify's zip-it-and-ship-it will attempt to bundle "./" |
67 |
| - // into the function's zip folder and the build will fail |
68 |
| - const pathToFile = `./${file}` |
69 |
| - const page = require(pathToFile) |
70 |
| - |
71 | 40 | // Render the page
|
72 | 41 | compat(page)(
|
73 | 42 | {
|
|
0 commit comments