feat: added vite+react+ts

This commit is contained in:
Boris Cherepanov
2025-10-03 00:05:32 +03:00
parent e4984dd29d
commit 8472e21955
21 changed files with 4774 additions and 0 deletions

24
client/.gitignore vendored Normal file
View File

@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

73
client/README.md Normal file
View File

@@ -0,0 +1,73 @@
# React + TypeScript + Vite
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
Currently, two official plugins are available:
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
## React Compiler
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
## Expanding the ESLint configuration
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
```js
export default defineConfig([
globalIgnores(['dist']),
{
files: ['**/*.{ts,tsx}'],
extends: [
// Other configs...
// Remove tseslint.configs.recommended and replace with this
tseslint.configs.recommendedTypeChecked,
// Alternatively, use this for stricter rules
tseslint.configs.strictTypeChecked,
// Optionally, add this for stylistic rules
tseslint.configs.stylisticTypeChecked,
// Other configs...
],
languageOptions: {
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
// other options...
},
},
])
```
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
```js
// eslint.config.js
import reactX from 'eslint-plugin-react-x'
import reactDom from 'eslint-plugin-react-dom'
export default defineConfig([
globalIgnores(['dist']),
{
files: ['**/*.{ts,tsx}'],
extends: [
// Other configs...
// Enable lint rules for React
reactX.configs['recommended-typescript'],
// Enable lint rules for React DOM
reactDom.configs.recommended,
],
languageOptions: {
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
// other options...
},
},
])
```

23
client/eslint.config.js Normal file
View File

@@ -0,0 +1,23 @@
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'
import { defineConfig, globalIgnores } from 'eslint/config'
export default defineConfig([
globalIgnores(['dist']),
{
files: ['**/*.{ts,tsx}'],
extends: [
js.configs.recommended,
tseslint.configs.recommended,
reactHooks.configs['recommended-latest'],
reactRefresh.configs.vite,
],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
},
])

13
client/index.html Normal file
View File

@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>client</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

3907
client/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

39
client/package.json Normal file
View File

@@ -0,0 +1,39 @@
{
"name": "client",
"private": true,
"version": "0.0.0",
"type": "module",
"engines": {
"node": "^20"
},
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"react": "^19.1.1",
"react-dom": "^19.1.1",
"react-router": "^7.9.3"
},
"devDependencies": {
"@eslint/js": "^9.36.0",
"@types/node": "^24.6.0",
"@types/react": "^19.1.16",
"@types/react-dom": "^19.1.9",
"@vitejs/plugin-react": "^5.0.4",
"eslint": "^9.36.0",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.22",
"globals": "^16.4.0",
"lint-staged": "^16.2.3",
"prettier": "^3.6.2",
"typescript": "~5.9.3",
"typescript-eslint": "^8.45.0",
"vite": "^7.1.7"
},
"lint-staged": {
"**/*": "prettier --write --ignore-unknown"
}
}

1
client/public/vite.svg Normal file
View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

3
client/src/.env.example Normal file
View File

@@ -0,0 +1,3 @@
VITE_API_BASE=/api
VITE_API_HOST=https://localhost
VITE_API_PORT=8081

23
client/src/.prettierrc Normal file
View File

@@ -0,0 +1,23 @@
{
"arrowParens": "always",
"bracketSameLine": false,
"objectWrap": "preserve",
"bracketSpacing": true,
"semi": true,
"experimentalOperatorPosition": "end",
"experimentalTernaries": false,
"singleQuote": true,
"jsxSingleQuote": false,
"quoteProps": "as-needed",
"trailingComma": "all",
"singleAttributePerLine": false,
"htmlWhitespaceSensitivity": "css",
"vueIndentScriptAndStyle": false,
"proseWrap": "preserve",
"insertPragma": false,
"printWidth": 80,
"requirePragma": false,
"tabWidth": 2,
"useTabs": false,
"embeddedLanguageFormatting": "auto"
}

0
client/src/index.css Normal file
View File

11
client/src/main.tsx Normal file
View File

@@ -0,0 +1,11 @@
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import { RouterProvider } from 'react-router/dom';
import { router } from './router';
import './index.css';
createRoot(document.getElementById('root')!).render(
<StrictMode>
<RouterProvider router={router} />
</StrictMode>,
);

View File

@@ -0,0 +1,238 @@
body {
font-family: Arial, sans-serif;
margin: 20px;
background: #f5f5f5;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
.section {
background: white;
margin: 20px 0;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
h1 {
color: #333;
}
h2 {
color: #666;
border-bottom: 1px solid #eee;
padding-bottom: 10px;
}
table {
width: 100%;
border-collapse: collapse;
margin: 10px 0;
}
th,
td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background: #f9f9f9;
}
.btn {
padding: 6px 12px;
margin: 2px;
border: none;
border-radius: 4px;
cursor: pointer;
}
.btn-primary {
background: #007bff;
color: white;
}
.btn-success {
background: #28a745;
color: white;
}
.btn-danger {
background: #dc3545;
color: white;
}
.btn-secondary {
background: #6c757d;
color: white;
}
.form-group {
margin: 10px 0;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.form-group input,
.form-group select {
width: 300px;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
}
/* Toast notifications */
.toast-container {
position: fixed;
top: 20px;
right: 20px;
z-index: 9999;
pointer-events: none;
}
.toast {
background: white;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
margin-bottom: 10px;
padding: 16px 20px;
min-width: 300px;
max-width: 400px;
position: relative;
transform: translateX(100%);
transition:
transform 0.3s ease-in-out,
opacity 0.3s ease-in-out;
opacity: 0;
pointer-events: auto;
border-left: 4px solid #007bff;
}
.toast.show {
transform: translateX(0);
opacity: 1;
}
.toast.success {
border-left-color: #28a745;
}
.toast.error {
border-left-color: #dc3545;
}
.toast-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
}
.toast-title {
font-weight: bold;
color: #333;
}
.toast-close {
background: none;
border: none;
font-size: 18px;
color: #999;
cursor: pointer;
padding: 0;
margin-left: 10px;
}
.toast-close:hover {
color: #666;
}
.toast-body {
color: #666;
line-height: 1.4;
}
.toast.success .toast-title {
color: #155724;
}
.toast.error .toast-title {
color: #721c24;
}
.tabs {
border-bottom: 1px solid #ddd;
margin-bottom: 20px;
}
.tab {
display: inline-block;
padding: 10px 20px;
cursor: pointer;
border-bottom: 2px solid transparent;
}
.tab.active {
border-bottom-color: #007bff;
background: #f8f9fa;
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
.loading {
text-align: center;
padding: 20px;
color: #666;
}
/* Modal styles */
.modal {
display: none;
position: fixed;
z-index: 10000;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
}
.modal.show {
display: flex;
align-items: center;
justify-content: center;
}
.modal-content {
background: white;
border-radius: 8px;
padding: 20px;
max-width: 600px;
width: 90%;
max-height: 80vh;
overflow-y: auto;
position: relative;
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
border-bottom: 1px solid #eee;
padding-bottom: 10px;
}
.modal-title {
font-size: 18px;
font-weight: bold;
color: #333;
}
.modal-close {
background: none;
border: none;
font-size: 24px;
color: #999;
cursor: pointer;
}
.modal-close:hover {
color: #666;
}
.modal-body {
margin-bottom: 20px;
}
.modal-footer {
display: flex;
justify-content: flex-end;
gap: 10px;
border-top: 1px solid #eee;
padding-top: 15px;
}
.cert-details {
font-family: monospace;
background: #f8f9fa;
border: 1px solid #e9ecef;
border-radius: 4px;
padding: 15px;
white-space: pre-wrap;
overflow-x: auto;
max-height: 300px;
}

View File

@@ -0,0 +1,339 @@
import { Outlet } from 'react-router';
import './home.css';
export const Home = () => {
return (
<div>
<div className="container">
<h1>Xray Admin Panel - Test Interface</h1>
{/* <!-- Toast notifications container --> */}
<div className="toast-container" id="toastContainer"></div>
<div className="tabs">
<div
className="tab active"
// onClick="showTab('dashboard')"
>
Dashboard
</div>
<div
className="tab"
// onClick="showTab('servers')"
>
Servers
</div>
<div
className="tab"
//onClick="showTab('templates')"
>
Inbound Templates
</div>
<div
className="tab"
// onClick="showTab('certificates')"
>
Certificates
</div>
<div
className="tab"
// onClick="showTab('inbounds')"
>
Inbound Binding
</div>
<div
className="tab"
// onClick="showTab('users')"
>
Users
</div>
</div>
{/* <!-- Dashboard --> */}
<div id="dashboard" className="tab-content active">
<div className="section">
<h2>Statistics</h2>
<p>
Servers: <span id="serverCount">Loading...</span>
</p>
<p>
Templates: <span id="templateCount">Loading...</span>
</p>
<p>
Certificates: <span id="certCount">Loading...</span>
</p>
<p>
Users: <span id="userCount">Loading...</span>
</p>
</div>
</div>
{/* <!-- Servers --> */}
<div id="servers" className="tab-content">
<div className="section">
<h2>Add Server</h2>
<form id="serverForm">
<div className="form-group">
<label>Name:</label>
<input type="text" id="serverName" required />
</div>
<div className="form-group">
<label>Hostname:</label>
<input type="text" id="serverHostname" required />
</div>
<div className="form-group">
<label>gRPC Port:</label>
<input type="number" id="serverPort" value="2053" />
</div>
<button type="submit" className="btn btn-primary">
Add Server
</button>
</form>
</div>
<div className="section">
<h2>Servers List</h2>
<div id="serversList" className="loading">
Loading...
</div>
</div>
</div>
{/* <!-- Templates --> */}
<div id="templates" className="tab-content">
<div className="section">
<h2>Add Template</h2>
<form id="templateForm">
<div className="form-group">
<label>Name:</label>
<input type="text" id="templateName" required />
</div>
<div className="form-group">
<label>Protocol:</label>
<select id="templateProtocol" required>
<option value="vless">VLESS</option>
<option value="vmess">VMess</option>
<option value="trojan">Trojan</option>
<option value="shadowsocks">Shadowsocks</option>
</select>
</div>
<div className="form-group">
<label>Default Port:</label>
<input type="number" id="templatePort" value="443" required />
</div>
<div className="form-group">
<label>
<input type="checkbox" id="templateTls" /> Requires TLS
</label>
</div>
<div className="form-group">
<label>Configuration Template:</label>
<textarea
id="templateConfig"
rows={6}
style={{
width: '300px',
}}
></textarea>
</div>
<button type="submit" className="btn btn-primary">
Add Template
</button>
</form>
</div>
<div className="section">
<h2>Templates List</h2>
<div id="templatesList" className="loading">
Loading...
</div>
</div>
</div>
{/* <!-- Certificates --> */}
<div id="certificates" className="tab-content">
<div className="section">
<h2>Add Certificate</h2>
<form id="certificateForm">
<div className="form-group">
<label>Name:</label>
<input type="text" id="certName" required />
</div>
<div className="form-group">
<label>Domain:</label>
<input
type="text"
id="certDomain"
placeholder="example.com"
required
/>
</div>
<div className="form-group">
<label>Certificate Type:</label>
<select id="certType" required>
<option value="self_signed">Self-Signed</option>
</select>
</div>
<div className="form-group">
<label>
<input type="checkbox" id="certAutoRenew" checked /> Auto
Renew
</label>
</div>
<button type="submit" className="btn btn-primary">
Generate Certificate
</button>
</form>
</div>
<div className="section">
<h2>Certificates List</h2>
<div id="certificatesList" className="loading">
Loading...
</div>
</div>
</div>
{/* <!-- Server Inbounds --> */}
<div id="inbounds" className="tab-content">
<div className="section">
<h2>Bind Template to Server</h2>
<form id="inboundForm">
<div className="form-group">
<label>Server:</label>
<select id="inboundServer" required>
<option value="">Select Server...</option>
</select>
</div>
<div className="form-group">
<label>Template:</label>
<select id="inboundTemplate" required>
<option value="">Select Template...</option>
</select>
</div>
<div className="form-group">
<label>Port:</label>
<input type="number" id="inboundPort" value="443" required />
</div>
<div className="form-group">
<label>Certificate:</label>
<select id="inboundCertificate">
<option value="">No Certificate</option>
</select>
</div>
<div className="form-group">
<label>
<input type="checkbox" id="inboundActive" checked /> Active
</label>
</div>
<button type="submit" className="btn btn-primary">
Bind Template
</button>
</form>
</div>
<div className="section">
<h2>Server Inbounds</h2>
<div id="inboundsList" className="loading">
Loading...
</div>
</div>
</div>
{/* <!-- Users --> */}
<div id="users" className="tab-content">
<div className="section">
<h2>Add User</h2>
<form id="userForm">
<div className="form-group">
<label>Name:</label>
<input type="text" id="userName" required />
</div>
<div className="form-group">
<label>Comment:</label>
<input type="text" id="userComment" />
</div>
<div className="form-group">
<label>Telegram ID:</label>
<input type="number" id="userTelegram" />
</div>
<button type="submit" className="btn btn-primary">
Add User
</button>
</form>
</div>
<div className="section">
<h2>Users List</h2>
<div id="usersList" className="loading">
Loading...
</div>
</div>
</div>
</div>
{/* <!-- Modal dialogs --> */}
<div id="editModal" className="modal">
<div className="modal-content">
<div className="modal-header">
<div className="modal-title" id="editModalTitle">
Edit Item
</div>
<button
className="modal-close"
// onClick="closeModal('editModal')"
>
&times;
</button>
</div>
<div className="modal-body" id="editModalBody">
{/* <!-- Content will be dynamically loaded --> */}
</div>
<div className="modal-footer">
<button
className="btn btn-secondary"
// onClick="closeModal('editModal')"
>
Cancel
</button>
<button
className="btn btn-primary"
id="saveEditBtn"
// onClick="saveEdit()"
>
Save
</button>
</div>
</div>
</div>
<div id="viewModal" className="modal">
<div className="modal-content">
<div className="modal-header">
<div className="modal-title" id="viewModalTitle">
View Details
</div>
<button
className="modal-close"
//onClick="closeModal('viewModal')"
>
&times;
</button>
</div>
<div className="modal-body" id="viewModalBody">
{/* <!-- Content will be dynamically loaded --> */}
</div>
<div className="modal-footer">
<button
className="btn btn-secondary"
// onClick="closeModal('viewModal')"
>
Close
</button>
</div>
</div>
</div>
<Outlet />
</div>
);
};

View File

@@ -0,0 +1 @@
export * from './home';

View File

@@ -0,0 +1 @@
export * from './home';

View File

@@ -0,0 +1 @@
export * from './router';

View File

@@ -0,0 +1,9 @@
import { createBrowserRouter } from 'react-router';
import { Home } from '../pages';
export const router = createBrowserRouter([
{
path: '/',
Component: Home,
},
]);

28
client/tsconfig.app.json Normal file
View File

@@ -0,0 +1,28 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2022",
"useDefineForClassFields": true,
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"module": "ESNext",
"types": ["vite/client"],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"noEmit": true,
"jsx": "react-jsx",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["src"]
}

7
client/tsconfig.json Normal file
View File

@@ -0,0 +1,7 @@
{
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
]
}

26
client/tsconfig.node.json Normal file
View File

@@ -0,0 +1,26 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"target": "ES2023",
"lib": ["ES2023"],
"module": "ESNext",
"types": ["node"],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"noEmit": true,
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["vite.config.ts"]
}

7
client/vite.config.ts Normal file
View File

@@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
})