Skip to content
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

bug/issue 1137 have adapted SSR pages return text/html content type #1138

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/cli/src/lifecycles/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@ async function bundleSsrPages(compilation) {
staticHtml = staticHtml.replace(\/\<content-outlet>(.*)<\\/content-outlet>\/s, data.body);
}
return new Response(staticHtml);
return new Response(staticHtml, {
headers: {
'Content-Type': 'text/html'
}
});
}
`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,20 @@ describe('Build Greenwood With: ', function() {
await runner.runCommand(cliPath, 'build');
});

// test SSR page
describe('Adapting an SSR Page', function() {
let dom;
let response;

before(async function() {
const req = new Request(new URL('http://localhost:8080/index'));
const { handler } = await import(new URL('./adapter-output/index.js', pathToFileURL(outputPath)));
const response = await handler(req);
const html = await response.text();

dom = new JSDOM(html);
response = await handler(req);
dom = new JSDOM(await response.text());
});

it('should have the expected content-type for the response', function() {
expect(response.headers.get('content-type')).to.be.equal('text/html');
});

it('should have the expected number of <app-card> components on the page', function() {
Expand All @@ -92,13 +95,18 @@ describe('Build Greenwood With: ', function() {

describe('Adapting an API Route', function() {
let data;
let response;

before(async function() {
const handler = (await import(new URL('./adapter-output/greeting.js', pathToFileURL(outputPath)))).handler;
const req = new Request(new URL('http://localhost:8080/api/greeting?name=Greenwood'));
const res = await handler(req);

data = await res.json();
response = await handler(req);
data = await response.json();
});

it('should have the expected content-type for the response', function() {
expect(response.headers.get('content-type')).to.be.equal('application/json');
});

it('should have the expected message from the API when a query is passed', function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ async function genericAdapter(compilation) {
await fs.mkdir(adapterOutputUrl);
}

console.log({ ssrPages, apiRoutes });

for (const page of ssrPages) {
const { id } = page;
const outputFormat = generateOutputFormat(id, 'page');
Expand Down
Loading