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

feat: 更换启动方式

parent c066cfe0
Subproject commit 7ecabd2d01902a5074aa0107b68c0d07f0c8531b
Subproject commit 8f3590c67c79232b367346c47e928935bbde0414
......@@ -65,6 +65,7 @@
"electron-log": "^5.0.0-beta.16",
"electron-packager": "^17.1.1",
"electron-store": "^8.1.0",
"express": "^4.18.2",
"fs-extra": "^11.1.0",
"glob": "^9.0.1",
"ioredis": "^5.3.2",
......
This diff is collapsed.
const config = require('../config/index')
var
http = require('http'),
fs = require('fs'),
url = require('url'),
path = require('path')
const express = require('express');
const http = require('http');
const fs = require('fs');
const path = require('path');
const { getContext } = require('../store');
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 入口
var root = path.join(...dirPath, 'index.html');
const root = path.join(dirPath, 'index.html');
//创建服务器
var server = http.createServer(function(request, response){
//获得ur的path 类似'/css/index.css'
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()) {
app.get('/paas/*', (req, res) => {
const urlPath = req.originalUrl.replace(/^\/paas/, '');
const filePath = path.join(dirPath, urlPath);
let contentType = null;
const extname = request.url.substring(request.url.lastIndexOf('.') + 1);
switch (extname) {
case 'html':
contentType = 'text/html';
break;
case 'js':
contentType = 'text/javascript';
break;
case 'css':
contentType = 'text/css';
break;
case 'json':
contentType = 'application/json';
break;
case 'png':
contentType = 'image/png';
break;
case 'jpg':
contentType = 'image/jpg';
break;
case 'wav':
contentType = 'audio/wav';
break;
}
if (contentType) {
// 发送200响应:
response.writeHead(200, {"Content-Type": contentType + ';charset=UTF-8'});
// 将文件流导向response:
fs.createReadStream(path.join(...dirPath, request.url)).pipe(response);
} else {
// 重定向为 root
fs.createReadStream(root).pipe(response);
}
} else {
// 发送404响应:
response.writeHead(404);
response.end('404 Not Found');
}
});
fs.stat(filePath, (err, stats) => {
if (!err && stats.isFile()) {
let contentType = null;
const extname = path.extname(filePath).substring(1);
switch (extname) {
case 'html':
contentType = 'text/html';
break;
case 'js':
contentType = 'text/javascript';
break;
case 'css':
contentType = 'text/css';
break;
case 'json':
contentType = 'application/json';
break;
case 'png':
contentType = 'image/png';
break;
case 'jpg':
contentType = 'image/jpg';
break;
case 'wav':
contentType = 'audio/wav';
break;
}
if (contentType) {
res.set('Content-Type', contentType + ';charset=UTF-8');
fs.createReadStream(filePath).pipe(res);
} else {
res.redirect('/');
}
} else {
res.status(404).send('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');
\ No newline at end of file
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 {
this.ready()
}
startPage() {
this.killProcess(this.config.configServer.port)
const win = this.createWindow(this.config.ideWinConfig.frontUrl, MAIN.WINDOW_TYPE.FILE)
this.startWin = win
}
......@@ -60,6 +60,7 @@ class Main {
})
app.on('window-all-closed', () => {
if (this.isIDEClose) {
this.killProcess(this.config.configServer.port)
this.killProcess(this.config.javaServer.port, () => {
handleClose(app, () => {
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