Skip to content

Commit c06df6f

Browse files
threehamsshellscape
authored andcommitted
fixes #258: skip compilers with no publicPath (#259)
* fixes #258: skip compilers with no publicPath * Add additional test, revert whitespace change
1 parent 0f9ccbe commit c06df6f

File tree

3 files changed

+59
-12
lines changed

3 files changed

+59
-12
lines changed

lib/util.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,21 @@ function getPaths(publicPath, compiler, url) {
2424
&& compilers[i].options.output
2525
&& compilers[i].options.output.publicPath;
2626

27-
if (compilerPublicPath.indexOf('/') === 0) {
28-
compilerPublicPathBase = compilerPublicPath;
29-
} else {
30-
// handle the case where compilerPublicPath is a URL with hostname
31-
compilerPublicPathBase = parse(compilerPublicPath).pathname;
32-
}
27+
if (compilerPublicPath) {
28+
if (compilerPublicPath.indexOf('/') === 0) {
29+
compilerPublicPathBase = compilerPublicPath;
30+
} else {
31+
// handle the case where compilerPublicPath is a URL with hostname
32+
compilerPublicPathBase = parse(compilerPublicPath).pathname;
33+
}
3334

34-
// check the url vs the path part of the compilerPublicPath
35-
if (url.indexOf(compilerPublicPathBase) === 0) {
36-
return {
37-
publicPath: compilerPublicPath,
38-
outputPath: compilers[i].outputPath
39-
};
35+
// check the url vs the path part of the compilerPublicPath
36+
if (url.indexOf(compilerPublicPathBase) === 0) {
37+
return {
38+
publicPath: compilerPublicPath,
39+
outputPath: compilers[i].outputPath
40+
};
41+
}
4042
}
4143
}
4244
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
module.exports = [{
4+
context: __dirname,
5+
entry: './foo.js',
6+
output: {
7+
filename: 'foo.js',
8+
path: '/client',
9+
publicPath: '/static/'
10+
}
11+
}, {
12+
context: __dirname,
13+
entry: './bar.js',
14+
output: {
15+
filename: 'bar.js',
16+
path: '/server'
17+
}
18+
}];

test/tests/server.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const request = require('supertest');
99
const middleware = require('../../');
1010
const webpackConfig = require('../fixtures/server-test/webpack.config');
1111
const webpackMultiConfig = require('../fixtures/server-test/webpack.array.config');
12+
const webpackClientServerConfig = require('../fixtures/server-test/webpack.client.server.config');
1213

1314
describe('Server', () => {
1415
let instance;
@@ -245,6 +246,32 @@ describe('Server', () => {
245246
});
246247
});
247248

249+
describe('MultiCompiler: One `publicPath`', () => {
250+
before((done) => {
251+
app = express();
252+
const compiler = webpack(webpackClientServerConfig);
253+
instance = middleware(compiler, {
254+
stats: 'errors-only',
255+
logLevel: 'silent'
256+
});
257+
app.use(instance);
258+
listen = listenShorthand(done);
259+
});
260+
after(close);
261+
262+
it('request to bundle file', (done) => {
263+
request(app).get('/static/foo.js').expect(200, done);
264+
});
265+
266+
it('request to nonexistent file', (done) => {
267+
request(app).get('/static/invalid.js').expect(404, done);
268+
});
269+
270+
it('request to non-public path', (done) => {
271+
request(app).get('/').expect(404, done);
272+
});
273+
});
274+
248275
describe('server side render', () => {
249276
let locals;
250277
before((done) => {

0 commit comments

Comments
 (0)