1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- 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.loadURL(decodeURIComponent(url));
- const isFocusOpenWin: number = handeGet("isFocusOpenWin");
- if (isFocusOpenWin == 1) {
- mainWindow!.show();
- mainWindow!.setAlwaysOnTop(true);
- }
- // mainWindow!.webContents.send("iframe", {
- // type: "iframe",
- // data: path,
- // });
- 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.loadURL(decodeURIComponent(path));
- const isFocusOpenWin: number = handeGet("isFocusOpenWin");
- if (isFocusOpenWin == 1) {
- mainWindow!.show();
- mainWindow!.setAlwaysOnTop(true);
- }
- // mainWindow!.webContents.send("iframe", {
- // type: "iframe",
- // data: path,
- // });
- 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.loadURL(decodeURIComponent(path));
- const isFocusOpenWin: number = handeGet("isFocusOpenWin");
- if (isFocusOpenWin == 1) {
- mainWindow!.show();
- mainWindow!.setAlwaysOnTop(true);
- }
- // mainWindow!.webContents.send("iframe", {
- // type: "iframe",
- // data: path,
- // });
- res.send({
- code: 200,
- msg: "成功" + new Date(),
- });
- });
- app.listen(3003, () => console.log("Example app listening on port 3003!"));
- };
|