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 1234 refine spa local dev routing for html requests #1251

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
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
Loading