-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Node adapter: handle prerendering and serving with query params (#6110)
* Node adapter: handle prerendering and serving with query params * Adding a changeset
- Loading branch information
Showing
11 changed files
with
121 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/node': patch | ||
--- | ||
|
||
Fixes support for prerendering and query params |
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
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
9 changes: 9 additions & 0 deletions
9
packages/integrations/node/test/fixtures/prerender/package.json
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,9 @@ | ||
{ | ||
"name": "@test/nodejs-encoded", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*", | ||
"@astrojs/node": "workspace:*" | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/integrations/node/test/fixtures/prerender/src/pages/one.astro
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,10 @@ | ||
--- | ||
--- | ||
<html> | ||
<head> | ||
<title>One</title> | ||
</head> | ||
<body> | ||
<h1>One</h1> | ||
</body> | ||
</html> |
11 changes: 11 additions & 0 deletions
11
packages/integrations/node/test/fixtures/prerender/src/pages/two.astro
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,11 @@ | ||
--- | ||
export const prerender = true; | ||
--- | ||
<html> | ||
<head> | ||
<title>Two</title> | ||
</head> | ||
<body> | ||
<h1>Two</h1> | ||
</body> | ||
</html> |
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,60 @@ | ||
import nodejs from '../dist/index.js'; | ||
import { loadFixture, createRequestAndResponse } from './test-utils.js'; | ||
import { expect } from 'chai'; | ||
import * as cheerio from 'cheerio'; | ||
import { fetch } from 'undici'; | ||
|
||
describe('Prerendering', () => { | ||
/** @type {import('./test-utils').Fixture} */ | ||
let fixture; | ||
let server; | ||
|
||
before(async () => { | ||
process.env.ASTRO_NODE_AUTOSTART = 'disabled'; | ||
fixture = await loadFixture({ | ||
root: './fixtures/prerender/', | ||
output: 'server', | ||
adapter: nodejs({ mode: 'standalone' }), | ||
}); | ||
await fixture.build(); | ||
const { startServer } = await await load(); | ||
let res = startServer(); | ||
server = res.server; | ||
}); | ||
|
||
after(async () => { | ||
await server.stop(); | ||
}); | ||
|
||
async function load() { | ||
const mod = await import('./fixtures/prerender/dist/server/entry.mjs'); | ||
return mod; | ||
} | ||
|
||
it('Can render SSR route', async () => { | ||
const res = await fetch(`http://${server.host}:${server.port}/one`); | ||
const html = await res.text(); | ||
const $ = cheerio.load(html); | ||
|
||
expect(res.status).to.equal(200); | ||
expect($('h1').text()).to.equal('One'); | ||
}); | ||
|
||
it('Can render prerendered route', async () => { | ||
const res = await fetch(`http://${server.host}:${server.port}/two`); | ||
const html = await res.text(); | ||
const $ = cheerio.load(html); | ||
|
||
expect(res.status).to.equal(200); | ||
expect($('h1').text()).to.equal('Two'); | ||
}); | ||
|
||
it('Can render prerendered route with query params', async () => { | ||
const res = await fetch(`http://${server.host}:${server.port}/two?foo=bar`); | ||
const html = await res.text(); | ||
const $ = cheerio.load(html); | ||
|
||
expect(res.status).to.equal(200); | ||
expect($('h1').text()).to.equal('Two'); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.