chore: sync local changes (2026-03-12)

This commit is contained in:
2026-03-12 18:58:40 +08:00
parent 1123d6aef2
commit 4cc8ec9486
21 changed files with 4561 additions and 270 deletions

View File

@@ -0,0 +1,53 @@
#!/bin/bash
# 前端构建和部署脚本
echo "========== 萌芽短链前端部署 =========="
# 安装依赖
echo "安装依赖..."
npm install
# 构建
echo "构建前端..."
npm run build
# 创建部署目录
echo "创建部署目录..."
mkdir -p /shumengya/www/mengyalinkfly-frontend
# 备份旧文件
if [ -d "/shumengya/www/mengyalinkfly-frontend/index.html" ]; then
echo "备份旧版本..."
backup_dir="/shumengya/www/mengyalinkfly-frontend-backup-$(date +%Y%m%d-%H%M%S)"
mkdir -p "$backup_dir"
cp -r /shumengya/www/mengyalinkfly-frontend/* "$backup_dir/"
fi
# 部署新文件
echo "部署新文件..."
cp -r dist/* /shumengya/www/mengyalinkfly-frontend/
# 复制nginx配置
echo "更新nginx配置..."
cp ../nginx.conf /etc/nginx/sites-available/mengyalinkfly
# 创建软链接(如果不存在)
if [ ! -L "/etc/nginx/sites-enabled/mengyalinkfly" ]; then
ln -s /etc/nginx/sites-available/mengyalinkfly /etc/nginx/sites-enabled/
fi
# 测试nginx配置
echo "测试nginx配置..."
nginx -t
# 重启nginx
if [ $? -eq 0 ]; then
echo "重启nginx..."
systemctl restart nginx
echo ""
echo "========== 部署完成 =========="
echo "前端地址http://localhost:8989"
else
echo "Nginx配置错误请检查"
exit 1
fi

View File

@@ -4,8 +4,13 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/png" href="/logo.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>萌芽短链</title>
<meta name="theme-color" content="#1a1a2e" />
<meta name="description" content="萌芽短链接,简单、快速的短链接生成工具" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="apple-mobile-web-app-title" content="萌芽短链" />
<link rel="apple-touch-icon" href="/logo.png" />
<title>萌芽短链</title>
</head>
<body>
<div id="root"></div>

View File

@@ -0,0 +1,41 @@
server {
listen 8989;
server_name mengyalinkfly-frontend; # 前端服务器IP
root /shumengya/www/mengyalinkfly-frontend;
index index.html index.htm;
# 短链跳转4位字符的路径直接转发到后端服务器支持wget等命令行工具
location ~ "^/[a-zA-Z0-9]{4}$" {
proxy_pass http://192.168.1.233:7878;
proxy_set_header Host short.api.shumengya.top;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# 后端 API 代理到后端服务器
location /api {
proxy_pass http://192.168.1.233:7878;
proxy_set_header Host short.api.shumengya.top;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# 前端路由
location / {
try_files $uri $uri/ /index.html;
}
# 禁止访问隐藏文件
location ~ /\. {
deny all;
}
# 设置静态文件缓存
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg)$ {
expires 30d;
add_header Cache-Control "public, immutable";
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -24,6 +24,7 @@
"eslint-plugin-react-hooks": "^7.0.1",
"eslint-plugin-react-refresh": "^0.4.24",
"globals": "^16.5.0",
"vite": "^7.2.2"
"vite": "^7.2.2",
"vite-plugin-pwa": "^1.2.0"
}
}

View File

@@ -1,9 +1,22 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import { BrowserRouter } from 'react-router-dom'
import { registerSW } from 'virtual:pwa-register'
import './index.css'
import App from './App.jsx'
// 注册 PWA Service Worker支持更新提示
if (import.meta.env.PROD) {
registerSW({
onNeedRefresh() {
// 可选:有新版本时提示用户刷新,当前为 autoUpdate 会自动更新
},
onOfflineReady() {
console.log('PWA: 内容已缓存,可离线使用')
}
})
}
createRoot(document.getElementById('root')).render(
<StrictMode>
<BrowserRouter>

View File

@@ -1,9 +1,58 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { VitePWA } from 'vite-plugin-pwa'
// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
plugins: [
react(),
VitePWA({
registerType: 'autoUpdate', // 自动更新 Service Worker也可选 'prompt' 提示用户
includeAssets: ['logo.png', 'favicon.ico'],
manifest: {
name: '萌芽短链',
short_name: '萌芽短链',
description: '简单、快速的短链接生成工具',
theme_color: '#1a1a2e',
background_color: '#16213e',
display: 'standalone',
orientation: 'portrait-primary',
scope: '/',
start_url: '/',
lang: 'zh-CN',
icons: [
{
src: '/logo.png',
sizes: '192x192',
type: 'image/png',
purpose: 'any'
},
{
src: '/logo.png',
sizes: '512x512',
type: 'image/png',
purpose: 'any maskable'
}
]
},
workbox: {
globPatterns: ['**/*.{js,css,html,ico,png,svg,woff2}'],
globIgnores: ['**/background/*.png'], // 背景图过大,不预缓存,在线时再加载
runtimeCaching: [
{
urlPattern: /^https?:\/\/.*\/api\/.*/i,
handler: 'NetworkFirst',
options: {
cacheName: 'api-cache',
expiration: { maxEntries: 32, maxAgeSeconds: 60 * 5 },
cacheableResponse: { statuses: [0, 200] },
networkTimeoutSeconds: 10
}
}
]
}
})
],
server: {
host: '0.0.0.0',
port: 5173,