Commit 94452185 authored by 韵晨龙's avatar 韵晨龙

feat: 更换启动方式

parent c066cfe0
Subproject commit 7ecabd2d01902a5074aa0107b68c0d07f0c8531b Subproject commit 8f3590c67c79232b367346c47e928935bbde0414
...@@ -65,6 +65,7 @@ ...@@ -65,6 +65,7 @@
"electron-log": "^5.0.0-beta.16", "electron-log": "^5.0.0-beta.16",
"electron-packager": "^17.1.1", "electron-packager": "^17.1.1",
"electron-store": "^8.1.0", "electron-store": "^8.1.0",
"express": "^4.18.2",
"fs-extra": "^11.1.0", "fs-extra": "^11.1.0",
"glob": "^9.0.1", "glob": "^9.0.1",
"ioredis": "^5.3.2", "ioredis": "^5.3.2",
......
This diff is collapsed.
const config = require('../config/index') const express = require('express');
var const http = require('http');
http = require('http'), const fs = require('fs');
fs = require('fs'), const path = require('path');
url = require('url'), const { getContext } = require('../store');
path = require('path')
const config = require('../config/index');
const log = getContext().log;
const app = express();
const { getContext } = require('../store')
const log = getContext().log
// 文件夹路径 // 文件夹路径
var dirPath = [__dirname, '../../baseServer/paas/']; const dirPath = path.join(__dirname, '../../baseServer/paas');
// 从命令行参数获取root目录,默认是当前目录;当前 index.html 入口 // 从命令行参数获取root目录,默认是当前目录;当前 index.html 入口
var root = path.join(...dirPath, 'index.html'); const root = path.join(dirPath, 'index.html');
//创建服务器 app.get('/paas/*', (req, res) => {
var server = http.createServer(function(request, response){ const urlPath = req.originalUrl.replace(/^\/paas/, '');
//获得ur的path 类似'/css/index.css' const filePath = path.join(dirPath, urlPath);
var pathName = url.parse(request.url).pathname;
//获得对应的本地文件路径 类似’static/css/index.css‘
var filePath = path.join(root);
//获取文件状态
fs.stat(filePath, function (err, stats) {
if (!err && stats.isFile()) {
fs.stat(filePath, (err, stats) => {
if (!err && stats.isFile()) {
let contentType = null; let contentType = null;
const extname = request.url.substring(request.url.lastIndexOf('.') + 1); const extname = path.extname(filePath).substring(1);
switch (extname) { switch (extname) {
case 'html': case 'html':
contentType = 'text/html'; contentType = 'text/html';
...@@ -48,21 +46,25 @@ var server = http.createServer(function(request, response){ ...@@ -48,21 +46,25 @@ var server = http.createServer(function(request, response){
break; break;
} }
if (contentType) { if (contentType) {
// 发送200响应: res.set('Content-Type', contentType + ';charset=UTF-8');
response.writeHead(200, {"Content-Type": contentType + ';charset=UTF-8'}); fs.createReadStream(filePath).pipe(res);
// 将文件流导向response:
fs.createReadStream(path.join(...dirPath, request.url)).pipe(response);
} else { } else {
// 重定向为 root res.redirect('/');
fs.createReadStream(root).pipe(response);
} }
} else { } else {
// 发送404响应: res.status(404).send('404 Not Found');
response.writeHead(404);
response.end('404 Not Found');
} }
}); });
}); });
server.listen(config.configServer.port);
log.info('表单驱动静态页面启动--success'); app.get('*', (req, res) => {
\ No newline at end of file res.sendFile(root);
});
app.get('/*', (req, res) => {
res.sendFile(root);
});
const server = http.createServer(app);
server.listen(config.configServer.port, () => {
log.info('表单驱动静态页面启动--success');
});
\ No newline at end of file
...@@ -22,7 +22,7 @@ class Main { ...@@ -22,7 +22,7 @@ class Main {
this.ready() this.ready()
} }
startPage() { startPage() {
this.killProcess(this.config.configServer.port)
const win = this.createWindow(this.config.ideWinConfig.frontUrl, MAIN.WINDOW_TYPE.FILE) const win = this.createWindow(this.config.ideWinConfig.frontUrl, MAIN.WINDOW_TYPE.FILE)
this.startWin = win this.startWin = win
} }
...@@ -60,6 +60,7 @@ class Main { ...@@ -60,6 +60,7 @@ class Main {
}) })
app.on('window-all-closed', () => { app.on('window-all-closed', () => {
if (this.isIDEClose) { if (this.isIDEClose) {
this.killProcess(this.config.configServer.port)
this.killProcess(this.config.javaServer.port, () => { this.killProcess(this.config.javaServer.port, () => {
handleClose(app, () => { handleClose(app, () => {
app.quit() app.quit()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment