-
Notifications
You must be signed in to change notification settings - Fork 89
fix: Return MiddlewareResponse obj for rewrite #2159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 15 commits
7bb63d8
f46ab43
52b12a9
1ec8d01
4816efc
243330d
4199c23
0689fca
f181b44
993cba6
3d3ac2a
23caa96
40ade6d
3a38588
f04c6b6
3353d66
983c8fe
29e5502
6a1e00d
f1c210d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const Rewrite = () => { | ||
return ( | ||
<div> | ||
<p>This should have been rewritten</p> | ||
</div> | ||
) | ||
} | ||
|
||
export default Rewrite | ||
|
||
taty2010 marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import * as React from 'react' | ||
|
||
const useHydrated = () => { | ||
const [hydrated, setHydrated] = React.useState(false) | ||
React.useEffect(() => { | ||
setHydrated(true) | ||
}, []) | ||
return hydrated | ||
} | ||
|
||
const Page = ({ message, showAd }) => { | ||
const hydrated = useHydrated() | ||
return ( | ||
<div> | ||
<p id="message">{message}</p> | ||
{hydrated && showAd ? ( | ||
<div> | ||
<p>This is an ad that isn't shown by default on static test 2 page</p> | ||
<img src="http://placekitten.com/400/300" /> | ||
</div> | ||
) : ( | ||
<p>No ads for me</p> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export async function getStaticProps() { | ||
return { | ||
props: { | ||
message: 'This is a static page', | ||
showAd: false, | ||
}, | ||
} | ||
} | ||
|
||
export default Page |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import spawn from 'cross-spawn' | ||
import { existsSync, readFileSync, unlinkSync, writeFileSync } from 'fs' | ||
import { writeFile } from 'fs-extra' | ||
import { fetch as undiciFetch } from 'undici' | ||
import { fetch as undiciFetch } from 'next/dist/compiled/undici' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we never figured out why the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It happened here c295bc2 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once we move to Node.js 18, |
||
import nodeFetch from 'node-fetch' | ||
import path from 'path' | ||
import qs from 'querystring' | ||
|
@@ -111,7 +111,7 @@ async function processChunkedResponse(response) { | |
* @param {string | number} appPort | ||
* @param {string} pathname | ||
* @param {Record<string, any> | string | undefined} [query] | ||
* @param {import("undici").RequestInit} [opts] | ||
* @param {import("next/dist/compiled/undici").RequestInit} [opts] | ||
* @returns {Promise<string>} | ||
*/ | ||
export function renderViaHTTP(appPort, pathname, query, opts) { | ||
|
@@ -121,11 +121,11 @@ export function renderViaHTTP(appPort, pathname, query, opts) { | |
/** | ||
* @param {string | number} appPort | ||
* @param {string} pathname | ||
* @param {Record<string, any> | string | undefined} query | ||
* @param {RequestInit} opts | ||
* @returns {Promise<Response>} | ||
* @param {Record<string, any> | string | null | undefined} [query] | ||
* @param {import('node-fetch').RequestInit} [opts] | ||
* @returns {Promise<Response & {buffer: any} & {headers: Headers}>} | ||
*/ | ||
export async function fetchViaHTTP(appPort, pathname, query = undefined, opts = undefined, useUndici = false) { | ||
export function fetchViaHTTP(appPort, pathname, query, opts, useUndici = false) { | ||
const url = `${pathname}${typeof query === 'string' ? query : query ? `?${qs.stringify(query)}` : ''}` | ||
const fetch = useUndici ? undiciFetch : nodeFetch | ||
const fullUrl = getFullUrl(appPort, url) | ||
|
Uh oh!
There was an error while loading. Please reload this page.