This commit is contained in:
黄心宇 2024-01-19 17:34:43 +08:00
parent ad929dca5b
commit ab069eb701
2 changed files with 8 additions and 5 deletions

View File

@ -1,6 +1,6 @@
import express from "express";
import "./window"
import {render} from "./render";
import { getDomObj } from "./window"
import { render } from "./render";
import { url } from "../src/ssrUrl";
const { createProxyMiddleware } = require('http-proxy-middleware');
@ -38,6 +38,7 @@ function excludePath(req, res, next) {
app.use(excludePath);
app.get('*',function (req,res) {
global.domObj = getDomObj()
render(req,res);
})

View File

@ -6,17 +6,19 @@ import axios from "axios";
const { JSDOM } = jsdom;
const html = fs.readFileSync(path.join(path.resolve('./build'),'index.html'),'utf-8');
const dom = new JSDOM(html);
const { window } = dom;
const { window } = new JSDOM(html);
const $ = require( "jquery" )( window )
global.window = window;
global.domObj = dom;
global.document = window.document;
global.navigator = window.navigator;
global.localStorage = {}
export const getDomObj = () => {
return new JSDOM(html)
}
// axios.get('https://gw.alipayobjects.com/os/lib/alipay/alex/2.0.19/bundle/alex.all.global.min.js')
// .then(response => {
// // 处理响应