后端:解耦配置的读取
前端:实现配置文件从环境变量获取
This commit is contained in:
parent
7f2a02dc61
commit
bd619e7519
3
frontend/.env
Normal file
3
frontend/.env
Normal file
@ -0,0 +1,3 @@
|
||||
VITE_APP_API='http://localhost:8000/api'
|
||||
VITE_APP_THEMES='@/themes'
|
||||
VITE_APP_PLUGINS='@/plugins'
|
28
frontend/eslint.config.js
Normal file
28
frontend/eslint.config.js
Normal file
@ -0,0 +1,28 @@
|
||||
import js from '@eslint/js'
|
||||
import globals from 'globals'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
import tseslint from 'typescript-eslint'
|
||||
|
||||
export default tseslint.config(
|
||||
{ ignores: ['dist'] },
|
||||
{
|
||||
extends: [js.configs.recommended, ...tseslint.configs.recommended],
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
languageOptions: {
|
||||
ecmaVersion: 2020,
|
||||
globals: globals.browser,
|
||||
},
|
||||
plugins: {
|
||||
'react-hooks': reactHooks,
|
||||
'react-refresh': reactRefresh,
|
||||
},
|
||||
rules: {
|
||||
...reactHooks.configs.recommended.rules,
|
||||
'react-refresh/only-export-components': [
|
||||
'warn',
|
||||
{ allowConstantExport: true },
|
||||
],
|
||||
},
|
||||
},
|
||||
)
|
@ -1,29 +0,0 @@
|
||||
// services/dependency-checker.ts
|
||||
|
||||
import { Dependency } from "../types/common";
|
||||
|
||||
/**
|
||||
* 依赖检查器服务
|
||||
*/
|
||||
export class DependencyChecker {
|
||||
/**
|
||||
* 检查依赖项是否满足要求
|
||||
* @param dependencies 需要检查的依赖项列表
|
||||
* @returns 是否所有依赖都满足要求
|
||||
*/
|
||||
static async checkDependencies(dependencies: Dependency[]): Promise<boolean> {
|
||||
for (const dep of dependencies) {
|
||||
const response = await fetch(`/api/dependencies/check`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(dep)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
console.error(`依赖检查失败: ${dep.id}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
11
frontend/src/env.d.ts
vendored
Normal file
11
frontend/src/env.d.ts
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
interface ImportMetaEnv {
|
||||
readonly VITE_APP_API: string
|
||||
readonly VITE_APP_THEMES: string
|
||||
readonly VITE_APP_PLUGINS: string
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
readonly env: ImportMetaEnv
|
||||
}
|
@ -8,6 +8,8 @@ import {createContext} from "react";
|
||||
export const serverAddressContext=createContext("localhost:8080")
|
||||
// 动态路由
|
||||
const RouterListener: React.FC = () => {
|
||||
const a=import.meta.env.VITE_APP_THEMES;
|
||||
console.log(a)
|
||||
const pathname = location.pathname.split("/");
|
||||
console.log(pathname)
|
||||
return (
|
||||
|
@ -1,7 +1,8 @@
|
||||
// page/page.tsx
|
||||
import React from "react";
|
||||
const THEMEPATH= "../../themes"
|
||||
const THEMEPATH= "@/themes"
|
||||
import {serverAddressContext} from "../main.tsx";
|
||||
|
||||
// 动态获取当前主题
|
||||
const getCurrentTheme = async (): Promise<string> => {
|
||||
return new Promise<string>((resolve) => {
|
||||
|
29
frontend/tsconfig.app.json
Normal file
29
frontend/tsconfig.app.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
"target": "ES2020",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "Bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"isolatedModules": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true,
|
||||
"paths": {
|
||||
"@/*": ["./*"]
|
||||
}
|
||||
},
|
||||
"include": ["src","utils","themes","public"]
|
||||
}
|
7
frontend/tsconfig.json
Normal file
7
frontend/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./tsconfig.app.json" },
|
||||
{ "path": "./tsconfig.node.json" }
|
||||
]
|
||||
}
|
24
frontend/tsconfig.node.json
Normal file
24
frontend/tsconfig.node.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||
"target": "ES2022",
|
||||
"lib": ["ES2023"],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "Bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"isolatedModules": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true,
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
12
frontend/vite.config.ts
Normal file
12
frontend/vite.config.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import {defineConfig} from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': __dirname,
|
||||
}
|
||||
}
|
||||
})
|
5
package.json
Normal file
5
package.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"react-helmet": "^6.1.0"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user