-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.js
More file actions
32 lines (27 loc) · 826 Bytes
/
agent.js
File metadata and controls
32 lines (27 loc) · 826 Bytes
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
'use strict';
const Koa = require('koa');
const cors = require('kcors');
const app = new Koa();
app.use(cors());
module.exports = agent => {
// 在这里写你的初始化逻辑
// 也可以通过 messenger 对象发送消息给 App Worker
// 但需要等待 App Worker 启动成功后才能发送,不然很可能丢失
agent.messenger.on('egg-ready', () => {
const {
clientConfig,
serverConfig,
templatePath,
port,
} = agent.config.webpackVue;
require('./lib/setup-dev-server')(app, port, templatePath, clientConfig, serverConfig, (bundle, renderOptions) => {
agent.messenger.sendToApp('webpack_success', {
bundle,
renderOptions,
});
});
app.listen(port, () => {
console.log(`server started at localhost:${port}`);
});
});
};