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()) {
let contentType = null; fs.stat(filePath, (err, stats) => {
const extname = request.url.substring(request.url.lastIndexOf('.') + 1); if (!err && stats.isFile()) {
switch (extname) { let contentType = null;
case 'html': const extname = path.extname(filePath).substring(1);
contentType = 'text/html'; switch (extname) {
break; case 'html':
case 'js': contentType = 'text/html';
contentType = 'text/javascript'; break;
break; case 'js':
case 'css': contentType = 'text/javascript';
contentType = 'text/css'; break;
break; case 'css':
case 'json': contentType = 'text/css';
contentType = 'application/json'; break;
break; case 'json':
case 'png': contentType = 'application/json';
contentType = 'image/png'; break;
break; case 'png':
case 'jpg': contentType = 'image/png';
contentType = 'image/jpg'; break;
break; case 'jpg':
case 'wav': contentType = 'image/jpg';
contentType = 'audio/wav'; break;
break; case 'wav':
} contentType = 'audio/wav';
if (contentType) { break;
// 发送200响应: }
response.writeHead(200, {"Content-Type": contentType + ';charset=UTF-8'}); if (contentType) {
// 将文件流导向response: res.set('Content-Type', contentType + ';charset=UTF-8');
fs.createReadStream(path.join(...dirPath, request.url)).pipe(response); fs.createReadStream(filePath).pipe(res);
} else { } else {
// 重定向为 root res.redirect('/');
fs.createReadStream(root).pipe(response); }
} } else {
} else { res.status(404).send('404 Not Found');
// 发送404响应: }
response.writeHead(404); });
response.end('404 Not Found'); });
}
}); app.get('*', (req, res) => {
res.sendFile(root);
});
app.get('/*', (req, res) => {
res.sendFile(root);
}); });
server.listen(config.configServer.port);
log.info('表单驱动静态页面启动--success'); const server = http.createServer(app);
\ No newline at end of file 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