Skip to content

Commit

Permalink
check for HTML accept type for SPA routes
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Jun 26, 2024
1 parent 4ce37fc commit a7b6b9b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/cli/src/plugins/resource/plugin-standard-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ class StandardHtmlResource extends ResourceInterface {
this.contentType = 'text/html';
}

async shouldServe(url) {
async shouldServe(url, request) {
const { protocol, pathname } = url;
const hasMatchingPageRoute = this.compilation.graph.find(node => node.route === pathname);
const isSPA = this.compilation.graph.find(node => node.isSPA) && pathname.indexOf('.') < 0;

return protocol.startsWith('http') && (hasMatchingPageRoute || isSPA);
return protocol.startsWith('http') && (hasMatchingPageRoute || (isSPA && request.headers.get('Accept').indexOf('text/html') >= 0));
}

async serve(url, request) {
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/test/cases/develop.spa/develop.spa.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('Develop Greenwood With: ', function() {
let body;

before(async function() {
response = await fetch(`${hostname}:${port}/`);
response = await fetch(`${hostname}:${port}/`, { headers: { 'Accept': 'text/html' } });
body = await response.clone().text();
});

Expand All @@ -103,7 +103,7 @@ describe('Develop Greenwood With: ', function() {
let body;

before(async function() {
response = await fetch(`http://127.0.0.1:${port}/artists/`);
response = await fetch(`http://127.0.0.1:${port}/artists/`, { headers: { 'Accept': 'text/html' } });
body = await response.clone().text();
});

Expand All @@ -129,7 +129,7 @@ describe('Develop Greenwood With: ', function() {
let body;

before(async function() {
response = await fetch(`http://127.0.0.1:${port}/artists/1`);
response = await fetch(`http://127.0.0.1:${port}/artists/1`, { headers: { 'Accept': 'text/html' } });
body = await response.clone().text();
});

Expand Down

0 comments on commit a7b6b9b

Please sign in to comment.