|
1 | 1 | const { join } = require("path");
|
2 | 2 | const { existsSync, readFileSync, writeFileSync } = require("fs-extra");
|
3 | 3 | const { logTitle, logItem } = require("../helpers/logger");
|
4 | | -const { CUSTOM_REDIRECTS_PATH } = require("../config"); |
| 4 | +const { |
| 5 | + CUSTOM_REDIRECTS_PATH, |
| 6 | + NEXT_IMAGE_FUNCTION_NAME, |
| 7 | +} = require("../config"); |
5 | 8 | const getSortedRoutes = require("../helpers/getSortedRoutes");
|
6 | 9 | const getNetlifyRoutes = require("../helpers/getNetlifyRoutes");
|
7 | 10 | const isRootCatchAllRedirect = require("../helpers/isRootCatchAllRedirect");
|
@@ -29,8 +32,14 @@ const setupRedirects = (publishPath) => {
|
29 | 32 | ...require("../pages/withoutProps/redirects"),
|
30 | 33 | ];
|
31 | 34 |
|
| 35 | + // Add next/image redirect to our image function |
| 36 | + nextRedirects.push({ |
| 37 | + route: "/_next/image* url=:url w=:width q=:quality", |
| 38 | + target: `/.netlify/functions/${NEXT_IMAGE_FUNCTION_NAME}?url=:url&w=:width&q=:quality`, |
| 39 | + }); |
| 40 | + |
32 | 41 | // Add _redirect section heading
|
33 | | - if(nextRedirects.length>=1)redirects.push("# Next-on-Netlify Redirects"); |
| 42 | + redirects.push("# Next-on-Netlify Redirects"); |
34 | 43 |
|
35 | 44 | // Sort routes: More-specific routes (e.g., static routing) precede
|
36 | 45 | // less-specific routes (e.g., catch-all)
|
|
0 commit comments