2017-12-01 09:51:35 +08:00
|
|
|
const ipcMain = require('electron').ipcMain;
|
|
|
|
|
|
|
|
function init(app) {
|
|
|
|
ipcMain.on('server-request', (event, arg) => {
|
|
|
|
const req = {};
|
|
|
|
req.url = arg.url;
|
|
|
|
req.method = arg.method;
|
|
|
|
req.body = arg.data;
|
|
|
|
req.headers = arg.headers;
|
2017-12-01 12:29:21 +08:00
|
|
|
req.session = {
|
|
|
|
loggedIn: true
|
|
|
|
};
|
2017-12-01 09:51:35 +08:00
|
|
|
|
|
|
|
const res = {
|
|
|
|
statusCode: 200
|
|
|
|
};
|
|
|
|
|
|
|
|
res.setHeader = function() {};
|
|
|
|
|
|
|
|
res.status = function(statusCode) {
|
|
|
|
res.statusCode = statusCode;
|
2018-04-06 11:17:19 +08:00
|
|
|
return res;
|
2017-12-01 09:51:35 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
res.send = function(obj) {
|
|
|
|
event.sender.send('server-response', {
|
|
|
|
requestId: arg.requestId,
|
|
|
|
statusCode: res.statusCode,
|
|
|
|
body: obj
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return app._router.handle(req, res, () => {});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = init;
|