-
Notifications
You must be signed in to change notification settings - Fork 22
/
app.js
34 lines (29 loc) · 1.11 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
const fs = require('fs');
const path = require('path');
const assert = require('assert');
const AssetsView = require('./lib/assets_view');
module.exports = app => {
const assetsConfig = app.config.assets;
if (assetsConfig.devServer.enable && assetsConfig.isLocalOrUnittest) {
let port = assetsConfig.devServer.port;
if (assetsConfig.devServer.autoPort === true) {
try {
port = fs.readFileSync(assetsConfig.devServer.portPath, 'utf8');
assetsConfig.devServer.port = Number(port);
} catch (err) {
// istanbul ignore next
throw new Error('check autoPort fail');
}
}
const protocol = app.options.https && assetsConfig.dynamicLocalIP ? 'https' : 'http';
assetsConfig.url = `${protocol}://127.0.0.1:${port}`;
}
// it should check manifest.json on deployment
if (!assetsConfig.isLocalOrUnittest) {
const manifestPath = path.join(app.config.baseDir, 'config/manifest.json');
assert(fs.existsSync(manifestPath), `${manifestPath} is required`);
assetsConfig.manifest = require(manifestPath);
}
app.view.use('assets', AssetsView);
};