Skip to content

Commit b0194e1

Browse files
authored
Merge pull request #133 from codingapi/dev
Dev
2 parents 60d8b43 + bf2e7a4 commit b0194e1

22 files changed

+388
-275
lines changed

admin-ui/mocks/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type {IncomingMessage} from "node:http";
2+
3+
export const parseBody = (req: IncomingMessage): Promise<any> => {
4+
return new Promise((resolve, reject) => {
5+
let body = '';
6+
req.on('data', (chunk) => {
7+
body += chunk.toString('utf-8');
8+
});
9+
req.on('end', () => {
10+
try {
11+
resolve(JSON.parse(body));
12+
} catch (e) {
13+
resolve({});
14+
}
15+
});
16+
req.on('error', (err) => reject(err));
17+
});
18+
};
19+
20+
export const getQuery = (req: IncomingMessage) => {
21+
const reqUrl = new URL(req.url || '', 'http://localhost');
22+
return Object.fromEntries(reqUrl.searchParams.entries());
23+
}

admin-ui/mocks/product.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
import Mock from "mockjs";
2-
import webpackMockServer from "webpack-mock-server";
2+
import type {IncomingMessage, ServerResponse} from "node:http";
3+
import {NextFunction} from "@rsbuild/core/dist-types/types/config";
34

4-
export default webpackMockServer.add((app, helper) => {
5-
app.get('/api/products', (req, res) => {
5+
export const productsHandler = async (req: IncomingMessage, res: ServerResponse, next: NextFunction) => {
6+
const url = req.url;
7+
const method = req.method?.toUpperCase();
8+
if(url?.startsWith("/api/products") && method === 'GET') {
69
const products = Mock.mock({
710
'list|100': [{
811
'id|+1': 1,
912
'name': '@name',
1013
'price|100-1000': 1,
1114
}]
1215
}).list;
13-
14-
res.json({
16+
res.setHeader('Content-Type', 'application/json');
17+
res.end(JSON.stringify({
1518
success: true,
16-
data:{
17-
list:products,
19+
data: {
20+
list: products,
1821
total: products.length
1922
},
20-
});
21-
});
22-
});
23+
}), 'utf-8');
24+
return;
25+
}
26+
27+
next();
28+
}

admin-ui/mocks/tsconfig.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

admin-ui/mocks/user.ts

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
1-
import webpackMockServer from "webpack-mock-server";
1+
import type {IncomingMessage, ServerResponse} from "node:http";
2+
import {NextFunction} from "@rsbuild/core/dist-types/types/config";
3+
import {parseBody} from "./index";
24

3-
export default webpackMockServer.add((app, helper) => {
4-
app.post('/user/login', (req, res) => {
5-
const username = req.body.username;
5+
export const usersHandler = async (req: IncomingMessage, res: ServerResponse, next: NextFunction) => {
6+
const url = req.url;
7+
const method = req.method?.toUpperCase();
8+
if(url?.startsWith("/user/login") && method === 'POST') {
9+
const body = await parseBody(req);
10+
const username = body.username || '';
11+
res.setHeader('Content-Type', 'application/json');
612
if(username==='admin'){
7-
res.json({
8-
success:true,
9-
data:{
13+
res.end(JSON.stringify({
14+
success: true,
15+
data: {
1016
'username': username,
11-
'token':'test token',
12-
'avatar':'/logo.png',
13-
'authorities': ['ROLE_ADMIN','ROLE_DEVELOPER'],
17+
'token': 'test token',
18+
'avatar': '/logo.png',
19+
'authorities': ['ROLE_ADMIN', 'ROLE_DEVELOPER'],
1420
}
15-
});
16-
return;
21+
}), 'utf-8');
22+
}else {
23+
res.end(JSON.stringify({
24+
success: true,
25+
data: {
26+
'username': username,
27+
'token': 'test token',
28+
'avatar': '/logo.png',
29+
'authorities': ['ROLE_USER'],
30+
}
31+
}), 'utf-8');
1732
}
33+
return;
34+
}
1835

19-
res.json({
20-
success:true,
21-
data:{
22-
'username': username,
23-
'token':'test token',
24-
'avatar':'/logo.png',
25-
'authorities': ['ROLE_USER'],
26-
}
27-
});
28-
});
29-
});
36+
next();
37+
}

admin-ui/package.json

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,15 @@
66
"@ant-design/icons": "^5.4.0",
77
"@ant-design/pro-components": "^2.8.7",
88
"@babel/standalone": "^7.25.6",
9-
"@codingapi/flow-pc": "^0.0.42",
10-
"@codingapi/form-pc": "^0.0.42",
11-
"@codingapi/ui-framework": "^0.0.42",
9+
"@codingapi/flow-pc": "^0.0.43",
10+
"@codingapi/form-pc": "^0.0.43",
11+
"@codingapi/ui-framework": "^0.0.43",
1212
"@dnd-kit/core": "^6.2.0",
1313
"@dnd-kit/sortable": "^9.0.0",
1414
"@handsontable/react-wrapper": "^15.0.0",
1515
"@logicflow/core": "^2.0.5",
1616
"@logicflow/extension": "^2.0.9",
1717
"@reduxjs/toolkit": "^2.2.7",
18-
"@types/babel__standalone": "^7.1.7",
19-
"@types/node": "^16.18.108",
20-
"@types/react": "^18.3.5",
21-
"@types/react-dom": "^18.3.0",
2218
"antd": "^5.20.6",
2319
"axios": "^1.7.7",
2420
"base64-js": "^1.5.1",
@@ -37,9 +33,10 @@
3733
"web-vitals": "^2.1.4"
3834
},
3935
"scripts": {
40-
"start": "webpack serve --config webpack.config.mock.js --open",
41-
"dev": "webpack serve --config webpack.config.dev.js --open",
42-
"build": "webpack --mode production --config webpack.config.prod.js",
36+
"dev": "rsbuild start --config rsbuild.config.dev.ts",
37+
"start": "rsbuild start",
38+
"mock": "rsbuild start --config rsbuild.config.mock.ts",
39+
"build": "rsbuild build",
4340
"test": "jest",
4441
"test:watch": "jest --watchAll"
4542
},
@@ -61,6 +58,15 @@
6158
]
6259
},
6360
"devDependencies": {
61+
"@module-federation/enhanced": "^0.17.0",
62+
"@module-federation/rsbuild-plugin": "^0.17.0",
63+
"@rsbuild/core": "^1.4.7",
64+
"@rsbuild/plugin-react": "^1.3.4",
65+
"@rsbuild/plugin-sass": "^1.3.3",
66+
"@types/babel__standalone": "^7.1.7",
67+
"@types/node": "^16.18.108",
68+
"@types/react": "^18.3.5",
69+
"@types/react-dom": "^18.3.0",
6470
"@babel/preset-env": "^7.26.0",
6571
"@babel/preset-react": "^7.26.3",
6672
"@babel/preset-typescript": "^7.26.0",
@@ -72,11 +78,8 @@
7278
"@types/lodash-es": "^4.17.12",
7379
"@types/mockjs": "^1.0.10",
7480
"babel-jest": "^29.7.0",
75-
"clean-webpack-plugin": "^4.0.0",
76-
"copy-webpack-plugin": "^12.0.2",
7781
"css-loader": "^7.1.2",
7882
"express": "^4.21.0",
79-
"html-webpack-plugin": "^5.6.0",
8083
"identity-obj-proxy": "^3.0.0",
8184
"jest": "^29.7.0",
8285
"jest-environment-jsdom": "^29.7.0",
@@ -87,11 +90,6 @@
8790
"style-loader": "^4.0.0",
8891
"ts-jest": "^29.3.2",
8992
"ts-loader": "^9.5.1",
90-
"ts-node": "^10.9.2",
91-
"webpack": "^5.94.0",
92-
"webpack-cli": "^5.1.4",
93-
"webpack-dev-server": "^5.1.0",
94-
"webpack-merge": "^6.0.1",
95-
"webpack-mock-server": "^1.0.23"
93+
"ts-node": "^10.9.2"
9694
}
9795
}

admin-ui/rsbuild.config.dev.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {defineConfig} from '@rsbuild/core';
2+
import commonConfig from './rsbuild.config';
3+
4+
export default defineConfig({
5+
...commonConfig,
6+
server: {
7+
port: 8000,
8+
proxy: {
9+
'/api': 'http://127.0.0.1:8090',
10+
'/open': 'http://127.0.0.1:8090',
11+
'/user': 'http://127.0.0.1:8090',
12+
},
13+
},
14+
})
15+

admin-ui/rsbuild.config.mock.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {defineConfig} from '@rsbuild/core';
2+
import commonConfig from './rsbuild.config';
3+
import {usersHandler} from "./mocks/user";
4+
import {productsHandler} from "./mocks/product";
5+
6+
export default defineConfig({
7+
...commonConfig,
8+
server: {
9+
port: 8000,
10+
},
11+
dev:{
12+
setupMiddlewares:(middlewares, devServer) => {
13+
if (!devServer) {
14+
throw new Error('webpack-dev-server is not defined');
15+
}
16+
console.log('mock server is running');
17+
middlewares.unshift(usersHandler,productsHandler);
18+
}
19+
}
20+
})
21+

admin-ui/rsbuild.config.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import * as path from 'path';
2+
import {defineConfig} from '@rsbuild/core';
3+
import {pluginReact} from '@rsbuild/plugin-react';
4+
import {pluginSass} from '@rsbuild/plugin-sass';
5+
// @ts-ignore
6+
import MonacoWebpackPlugin from 'monaco-editor-webpack-plugin';
7+
import {pluginModuleFederation} from '@module-federation/rsbuild-plugin';
8+
9+
export default defineConfig({
10+
plugins: [
11+
pluginReact(),
12+
pluginSass(),
13+
pluginModuleFederation({
14+
name: "AdminUI",
15+
shared: {
16+
react: {
17+
requiredVersion: '^18.3.1',
18+
singleton: true,
19+
strictVersion: false,
20+
},
21+
'react-dom': {
22+
requiredVersion: '^18.3.1',
23+
singleton: true,
24+
strictVersion: false,
25+
},
26+
}
27+
}, {
28+
ssr: false,
29+
ssrDir: path.resolve(__dirname, 'ssr'),
30+
environment: 'development',
31+
}),
32+
],
33+
server:{
34+
port: 8000,
35+
},
36+
source: {
37+
entry: {
38+
index: './src/entry.tsx',
39+
},
40+
decorators: {
41+
version: 'legacy',
42+
},
43+
},
44+
resolve:{
45+
alias:{
46+
'@': path.resolve(__dirname, 'src'),
47+
react: path.resolve(__dirname, 'node_modules/react'),
48+
'react-dom': path.resolve(__dirname, 'node_modules/react-dom'),
49+
}
50+
},
51+
html: {
52+
template: './public/index.html',
53+
},
54+
performance: {
55+
chunkSplit: {
56+
strategy: 'split-by-size',
57+
minSize: 10000,
58+
maxSize: 30000,
59+
},
60+
},
61+
tools: {
62+
rspack: (config) => {
63+
config.plugins.push(
64+
new MonacoWebpackPlugin({
65+
languages: ['javascript', 'typescript', 'json', 'css', 'html'],
66+
features: ['!gotoSymbol']
67+
}),
68+
);
69+
config.ignoreWarnings = [
70+
(warning) =>
71+
typeof warning.message === 'string' &&
72+
warning.message.includes('Critical dependency: require function is used'),
73+
];
74+
return config;
75+
}
76+
}
77+
});

admin-ui/src/entry.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import("./index");

mobile-ui/mocks/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type {IncomingMessage} from "node:http";
2+
3+
export const parseBody = (req: IncomingMessage): Promise<any> => {
4+
return new Promise((resolve, reject) => {
5+
let body = '';
6+
req.on('data', (chunk) => {
7+
body += chunk.toString('utf-8');
8+
});
9+
req.on('end', () => {
10+
try {
11+
resolve(JSON.parse(body));
12+
} catch (e) {
13+
resolve({});
14+
}
15+
});
16+
req.on('error', (err) => reject(err));
17+
});
18+
};
19+
20+
export const getQuery = (req: IncomingMessage) => {
21+
const reqUrl = new URL(req.url || '', 'http://localhost');
22+
return Object.fromEntries(reqUrl.searchParams.entries());
23+
}

0 commit comments

Comments
 (0)