mirror of
https://github.com/wallace5303/ee-core.git
synced 2026-04-05 15:39:03 +08:00
主进程服务支持https
This commit is contained in:
@@ -234,7 +234,11 @@ module.exports = appInfo => {
|
||||
protocol: 'http://',
|
||||
host: '127.0.0.1',
|
||||
port: 7072, // 默认端口(如果端口被使用,则随机获取一个)
|
||||
options: {}
|
||||
options: {},
|
||||
ssl: {
|
||||
key: '',
|
||||
cert: ''
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
31
lib/eeApp.js
31
lib/eeApp.js
@@ -1,10 +1,12 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const getPort = require('get-port');
|
||||
const {app, BrowserWindow, BrowserView, Menu} = require('electron');
|
||||
const BaseApp = require('./baseApp');
|
||||
const is = require('is-type-of');
|
||||
const Koa = require('koa');
|
||||
const koaServe = require('koa-static');
|
||||
const https = require('https');
|
||||
const utilsCommon = require('../utils/common');
|
||||
|
||||
class EeApp extends BaseApp {
|
||||
@@ -236,9 +238,29 @@ class EeApp extends BaseApp {
|
||||
url += '/' + hostInfo.indexPage;
|
||||
}
|
||||
|
||||
koaApp.listen(mainServer.port, () => {
|
||||
self.loadMainUrl(mode, url);
|
||||
});
|
||||
const isHttps = mainServer.protocol == 'https://' ? true : false;
|
||||
if (isHttps) {
|
||||
const keyFile = path.join(this.config.homeDir, mainServer.ssl.key);
|
||||
const certFile = path.join(this.config.homeDir, mainServer.ssl.cert);
|
||||
assert(fs.existsSync(keyFile), 'ssl key file is required');
|
||||
assert(fs.existsSync(certFile), 'ssl cert file is required');
|
||||
|
||||
const sslOpt = {
|
||||
key: fs.readFileSync(keyFile),
|
||||
cert: fs.readFileSync(certFile)
|
||||
};
|
||||
https.createServer(sslOpt, koaApp.callback()).listen(mainServer.port, (err) => {
|
||||
if (err) {
|
||||
self.coreLogger.info('[error] ', err);
|
||||
return
|
||||
}
|
||||
self.loadMainUrl(mode, url);
|
||||
});
|
||||
} else {
|
||||
koaApp.listen(mainServer.port, () => {
|
||||
self.loadMainUrl(mode, url);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -246,7 +268,8 @@ class EeApp extends BaseApp {
|
||||
*/
|
||||
loadMainUrl (type, url) {
|
||||
const mainServer = this.config.mainServer;
|
||||
this.logger.info('main page is env: %s, type: %s, App running at: %s', this.config.env, type, url);
|
||||
this.logger.info('[main server] env: %s, type: %s', this.config.env, type);
|
||||
this.logger.info('[main server] App running at: %s', url);
|
||||
this.electron.mainWindow.loadURL(url, mainServer.options);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ee-core",
|
||||
"version": "1.5.0",
|
||||
"version": "1.5.1-beta.1",
|
||||
"description": "ee core",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user