Skip to content

Commit

Permalink
updates post ResourceInterface changes from release branch
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Feb 18, 2021
1 parent eb3ac64 commit 1fa9dc0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
6 changes: 3 additions & 3 deletions packages/cli/src/commands/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ module.exports = runDevServer = async () => {
return provider;
})];

servers.forEach((server) => {
server.start();
});
return Promise.all(servers.map(async (server) => {
return server.start();
}));
});
} catch (err) {
reject(err);
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/lifecycles/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ function getDevServer(compilation) {
// allow intercepting of urls
app.use(async (ctx) => {
const modifiedResources = resources.concat(
pluginNodeModules.provider(compilation),
pluginLiveReloadResource.provider(compilationCopy)
pluginLiveReloadResource.provider(compilation)
);

const reducedResponse = await modifiedResources.reduce(async (responsePromise, resource) => {
const body = await responsePromise;
const { url, headers } = ctx;
const { url } = ctx;
const { headers } = ctx.response;
const shouldIntercept = await resource.shouldIntercept(url, body, headers);

if (shouldIntercept) {
Expand Down
16 changes: 6 additions & 10 deletions packages/cli/src/plugins/server/plugin-livereload.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,16 @@ class LiveReloadServer extends ServerInterface {
class LiveReloadResource extends ResourceInterface {

async shouldIntercept(url) {
return Promise.resolve(path.extname(url) === '');
return Promise.resolve(path.extname(url) === '' && process.env.__GWD_COMMAND__ === 'develop'); // eslint-disable-line no-underscore-dangle
}

async intercept(body) {
async intercept(url, body) {
return new Promise((resolve, reject) => {
try {
let contents = body;

if (process.env.__GWD_COMMAND__ === 'develop') { // eslint-disable-line no-underscore-dangle
contents = contents.replace('</head>', `
<script src="http://localhost:35729/livereload.js?snipver=1"></script>
</head>
`);
}
const contents = body.replace('</head>', `
<script src="http://localhost:35729/livereload.js?snipver=1"></script>
</head>
`);

resolve(contents);
} catch (e) {
Expand Down

0 comments on commit 1fa9dc0

Please sign in to comment.