mirror of
				https://github.com/linux-do/new-api.git
				synced 2025-11-04 21:33:41 +08:00 
			
		
		
		
	feat: vite
This commit is contained in:
		
							
								
								
									
										4
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								main.go
									
									
									
									
									
								
							@@ -20,10 +20,10 @@ import (
 | 
			
		||||
	_ "net/http/pprof"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
//go:embed web/build
 | 
			
		||||
//go:embed web/dist
 | 
			
		||||
var buildFS embed.FS
 | 
			
		||||
 | 
			
		||||
//go:embed web/build/index.html
 | 
			
		||||
//go:embed web/dist/index.html
 | 
			
		||||
var indexPage []byte
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,7 @@ func SetApiRouter(router *gin.Engine) {
 | 
			
		||||
		apiRouter.GET("/status/test", middleware.AdminAuth(), controller.TestStatus)
 | 
			
		||||
		apiRouter.GET("/notice", controller.GetNotice)
 | 
			
		||||
		apiRouter.GET("/about", controller.GetAbout)
 | 
			
		||||
		apiRouter.GET("/midjourney", controller.GetMidjourney)
 | 
			
		||||
		//apiRouter.GET("/midjourney", controller.GetMidjourney)
 | 
			
		||||
		apiRouter.GET("/home_page_content", controller.GetHomePageContent)
 | 
			
		||||
		apiRouter.GET("/verification", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.SendEmailVerification)
 | 
			
		||||
		apiRouter.GET("/reset_password", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.SendPasswordResetEmail)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										19
									
								
								web/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								web/index.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
<!DOCTYPE html>
 | 
			
		||||
<html lang="en">
 | 
			
		||||
  <head>
 | 
			
		||||
    <meta charset="utf-8" />
 | 
			
		||||
    <link rel="icon" href="/logo.png" />
 | 
			
		||||
    <meta name="viewport" content="width=device-width, initial-scale=1" />
 | 
			
		||||
    <meta name="theme-color" content="#ffffff" />
 | 
			
		||||
    <meta
 | 
			
		||||
      name="description"
 | 
			
		||||
      content="OpenAI 接口聚合管理,支持多种渠道包括 Azure,可用于二次分发管理 key,仅单可执行文件,已打包好 Docker 镜像,一键部署,开箱即用"
 | 
			
		||||
    />
 | 
			
		||||
    <title>New API</title>
 | 
			
		||||
  </head>
 | 
			
		||||
  <body>
 | 
			
		||||
    <noscript>You need to enable JavaScript to run this app.</noscript>
 | 
			
		||||
    <div id="root"></div>
 | 
			
		||||
    <script type="module" src="/src/index.js"></script>
 | 
			
		||||
  </body>
 | 
			
		||||
</html>
 | 
			
		||||
@@ -2,6 +2,7 @@
 | 
			
		||||
  "name": "react-template",
 | 
			
		||||
  "version": "0.1.0",
 | 
			
		||||
  "private": true,
 | 
			
		||||
  "type": "module",
 | 
			
		||||
  "dependencies": {
 | 
			
		||||
    "@douyinfe/semi-icons": "^2.46.1",
 | 
			
		||||
    "@douyinfe/semi-ui": "^2.46.1",
 | 
			
		||||
@@ -21,14 +22,13 @@
 | 
			
		||||
    "react-toastify": "^9.0.8",
 | 
			
		||||
    "react-turnstile": "^1.0.5",
 | 
			
		||||
    "semantic-ui-css": "^2.5.0",
 | 
			
		||||
    "semantic-ui-react": "^2.1.3",
 | 
			
		||||
    "usehooks-ts": "^2.9.1"
 | 
			
		||||
    "semantic-ui-react": "^2.1.3"
 | 
			
		||||
  },
 | 
			
		||||
  "scripts": {
 | 
			
		||||
    "start": "react-scripts start",
 | 
			
		||||
    "build": "react-scripts build",
 | 
			
		||||
    "test": "react-scripts test",
 | 
			
		||||
    "eject": "react-scripts eject"
 | 
			
		||||
    "dev": "vite",
 | 
			
		||||
    "build": "vite build",
 | 
			
		||||
    "lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
 | 
			
		||||
    "preview": "vite preview"
 | 
			
		||||
  },
 | 
			
		||||
  "eslintConfig": {
 | 
			
		||||
    "extends": [
 | 
			
		||||
@@ -50,7 +50,9 @@
 | 
			
		||||
  },
 | 
			
		||||
  "devDependencies": {
 | 
			
		||||
    "prettier": "2.8.8",
 | 
			
		||||
    "typescript": "4.4.2"
 | 
			
		||||
    "typescript": "4.4.2",
 | 
			
		||||
    "vite": "^5.2.0",
 | 
			
		||||
    "@vitejs/plugin-react": "^4.2.1"
 | 
			
		||||
  },
 | 
			
		||||
  "prettier": {
 | 
			
		||||
    "singleQuote": true,
 | 
			
		||||
 
 | 
			
		||||
@@ -41,7 +41,7 @@ const Footer = () => {
 | 
			
		||||
              href="https://github.com/Calcium-Ion/new-api"
 | 
			
		||||
              target="_blank" rel="noreferrer"
 | 
			
		||||
            >
 | 
			
		||||
              New API {process.env.REACT_APP_VERSION}{' '}
 | 
			
		||||
              New API {import.meta.env.VITE_REACT_APP_VERSION}{' '}
 | 
			
		||||
            </a>
 | 
			
		||||
            由{' '}
 | 
			
		||||
            <a href="https://github.com/Calcium-Ion" target="_blank" rel="noreferrer">
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@ import { showError } from './utils';
 | 
			
		||||
import axios from 'axios';
 | 
			
		||||
 | 
			
		||||
export const API = axios.create({
 | 
			
		||||
  baseURL: process.env.REACT_APP_SERVER ? process.env.REACT_APP_SERVER : '',
 | 
			
		||||
  baseURL: import.meta.env.VITE_REACT_APP_SERVER_URL ? import.meta.env.VITE_REACT_APP_SERVER_URL : '',
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
API.interceptors.response.use(
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										38
									
								
								web/vite.config.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								web/vite.config.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
			
		||||
import { defineConfig, transformWithEsbuild } from 'vite';
 | 
			
		||||
import react from '@vitejs/plugin-react';
 | 
			
		||||
 | 
			
		||||
// https://vitejs.dev/config/
 | 
			
		||||
export default defineConfig({
 | 
			
		||||
  plugins: [
 | 
			
		||||
    {
 | 
			
		||||
      name: 'treat-js-files-as-jsx',
 | 
			
		||||
      async transform(code, id) {
 | 
			
		||||
        if (!id.match(/src\/.*\.js$/))  return null
 | 
			
		||||
 | 
			
		||||
        // Use the exposed transform from vite, instead of directly
 | 
			
		||||
        // transforming with esbuild
 | 
			
		||||
        return transformWithEsbuild(code, id, {
 | 
			
		||||
          loader: 'jsx',
 | 
			
		||||
          jsx: 'automatic',
 | 
			
		||||
        })
 | 
			
		||||
      },
 | 
			
		||||
    },
 | 
			
		||||
    react(),
 | 
			
		||||
  ],
 | 
			
		||||
  optimizeDeps: {
 | 
			
		||||
    force: true,
 | 
			
		||||
    esbuildOptions: {
 | 
			
		||||
      loader: {
 | 
			
		||||
        '.js': 'jsx',
 | 
			
		||||
      },
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  server: {
 | 
			
		||||
    proxy: {
 | 
			
		||||
      '/api': {
 | 
			
		||||
        target: "http://localhost:3000",
 | 
			
		||||
        changeOrigin: true,
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
});
 | 
			
		||||
		Reference in New Issue
	
	Block a user