Skip to content
Open
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
9 changes: 7 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ module.exports = app => {
throw new Error('check autoPort fail');
}
}
const protocol = app.options.https && assetsConfig.dynamicLocalIP ? 'https' : 'http';
assetsConfig.url = `${protocol}://127.0.0.1:${port}`;
// if not set url,it will be `127.0.0.1:${devServer.port}`
if (assetsConfig.url) {
assetsConfig.url = `${assetsConfig.url}:${port}`;
} else {
const protocol = app.options.https && assetsConfig.dynamicLocalIP ? 'https' : 'http';
assetsConfig.url = `${protocol}://127.0.0.1:${port}`;
}
}

// it should check manifest.json on deployment
Expand Down
2 changes: 1 addition & 1 deletion config/config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = appInfo => ({
/**
* assets options
* @member Config#assets
* @property {String} url - the host of the assets, it will be `http://127.0.0.1:${devServer.port}` in development.
* @property {String} url - the host of the assets,if not set,it will be `127.0.0.1:${devServer.port}` in development.
* @property {String} publicPath - the base path of the assets
* @property {String} templatePath - the file path of template rendering html
* @property {String} templateViewEngine - the view engine for rendering template
Expand Down
20 changes: 20 additions & 0 deletions test/assets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,26 @@ describe('test/assets.test.js', () => {
});
});

describe('custom dev assets.url', () => {
let app;

before(() => {
mock.env('local');
app = mock.cluster({
baseDir: 'apps/custom-assets-url',
});
return app.ready();
});
after(() => app.close());

it('should GET /', () => {
return app.httpRequest()
.get('/')
.expect(/<link rel="stylesheet" href="http:\/\/local.test.cn:8000\/index.css" \/>/)
.expect(200);
});
});

describe('https assets.url with dynamicLocalIP', () => {
let app;

Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/apps/custom-assets-url/config/config.local.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

exports.assets = {
url: 'http://local.test.cn',
};