-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gatsby): use pathPrefix for SSR/DSG page-data requests with `gats…
…by serve` (#36231) * test * wait with proxy until serve is up * fix(gatsby): use pathPrefix for SSR/DSG page-data requests with gatsby serve
- Loading branch information
Showing
7 changed files
with
118 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
const handler = require(`serve-handler`) | ||
const http = require(`http`) | ||
const path = require(`path`) | ||
const httpProxy = require("http-proxy") | ||
const waitOn = require("wait-on") | ||
|
||
const server = http.createServer((request, response) => | ||
handler(request, response, { | ||
public: path.resolve(`assets`), | ||
headers: [ | ||
{ | ||
source: `**/*`, | ||
headers: [ | ||
{ | ||
key: `Access-Control-Allow-Origin`, | ||
value: `*`, | ||
}, | ||
], | ||
}, | ||
], | ||
}) | ||
) | ||
waitOn( | ||
{ | ||
resources: [`http://localhost:9000/blog/`], | ||
}, | ||
function (err) { | ||
if (err) { | ||
console.error(err) | ||
process.exit(1) | ||
} | ||
|
||
const proxy = httpProxy.createProxyServer() | ||
const server = http.createServer((request, response) => | ||
proxy.web(request, response, { target: "http://localhost:9000" }) | ||
) | ||
|
||
server.listen(9001, () => { | ||
console.log(`Running at http://localhost:9001`) | ||
}) | ||
server.listen(9001, () => { | ||
console.log(`Assets server running at http://localhost:9001`) | ||
}) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as React from "react" | ||
import { Link } from "gatsby" | ||
|
||
import Layout from "../components/layout" | ||
|
||
const SSRPage = ({ serverData }) => ( | ||
<Layout> | ||
<h1>Hi from the SSR page</h1> | ||
<p>Welcome to SSR page</p> | ||
<Link data-testid="index-link" to="/"> | ||
Go back to the homepage | ||
</Link> | ||
<code data-testid="server-data">{serverData?.dataFromServer}</code> | ||
</Layout> | ||
) | ||
|
||
export default SSRPage | ||
|
||
export function getServerData() { | ||
return { | ||
props: { | ||
dataFromServer: `foo`, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters