12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- import express from "express";
- import cors from "cors";
- import { mainWindow } from "../win/mainWin";
- import log from "electron-log/main";
- import { handeGet } from "./store";
- export const initExpress = () => {
- const app = express();
- app.use(express.json());
- app.use(express.urlencoded({ extended: false }));
- app.use(cors());
- app.get("/iframe", async (req, res) => {
- const { path, Path } = req.query;
- console.log("🚀 ~ app.get ~ req.query:", req.query);
- const url = path || Path;
- if (!url) {
- res.send({
- code: 10001,
- msg: "缺少path参数" + new Date(),
- });
- log.error("缺少path参数" + new Date());
- return;
- }
- mainWindow!.webContents.send("iframe", {
- type: "iframe",
- data: path,
- });
- // mainWindow!.webContents.loadURL(decodeURIComponent(url));
- const isFocusOpenWin: number = handeGet("isFocusOpenWin");
- if (isFocusOpenWin == 1) {
- mainWindow!.show();
- mainWindow!.setAlwaysOnTop(true);
- }
- res.send({
- code: 200,
- msg: "成功" + new Date(),
- });
- });
- app.get("/iframe/:path", async (req, res) => {
- const { path } = req.params;
- if (!path) {
- res.send({
- code: 10001,
- msg: "缺少path参数" + new Date(),
- });
- log.error("缺少path参数" + new Date());
- return;
- }
- mainWindow!.webContents.send("iframe", {
- type: "iframe",
- data: path,
- });
- // mainWindow!.webContents.loadURL(decodeURIComponent(path));
- const isFocusOpenWin: number = handeGet("isFocusOpenWin");
- if (isFocusOpenWin == 1) {
- mainWindow!.show();
- mainWindow!.setAlwaysOnTop(true);
- }
- res.send({
- code: 200,
- msg: "成功" + new Date(),
- });
- });
- app.post("/iframe", async (req, res) => {
- const body = req.body;
- console.log("🚀 ~ app.get ~ req.body:", body);
- const { path } = req.body;
- if (!path) {
- res.send({
- code: 10001,
- msg: "缺少path参数" + new Date(),
- });
- log.error("缺少path参数" + new Date());
- return;
- }
- mainWindow!.webContents.send("iframe", {
- type: "iframe",
- data: path,
- });
- // mainWindow!.webContents.loadURL(decodeURIComponent(path));
- const isFocusOpenWin: number = handeGet("isFocusOpenWin");
- if (isFocusOpenWin == 1) {
- mainWindow!.show();
- mainWindow!.setAlwaysOnTop(true);
- }
- res.send({
- code: 200,
- msg: "成功" + new Date(),
- });
- });
- app.listen(3003, () => console.log("Example app listening on port 3003!"));
- };
|