feat: 完善后台部署与API前缀配置
This commit is contained in:
1 parent
c821d6c7db
commit
2b1035dbc8
7 files changed
+54
-2
No files matched your search
@@ -0,0 +1,4 @@
|
||||
VITE_APP_BASE_PATH=/admin/
|
||||
VITE_API_BASE_URL=/api
|
||||
VITE_DEV_API_TARGET=http://localhost:3001
|
||||
ADMIN_PORT=3000
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ApiClient } from "@personal-brand/api-client";
|
||||
|
||||
export const apiBaseUrl = import.meta.env.VITE_API_BASE_URL ?? "http://localhost:3001";
|
||||
export const apiBaseUrl = import.meta.env.VITE_API_BASE_URL ?? "/api";
|
||||
export async function authenticatedFetch(
|
||||
input: RequestInfo | URL,
|
||||
init?: RequestInit,
|
||||
|
||||
Vendored
+1
@@ -1,5 +1,6 @@
|
||||
interface ImportMetaEnv {
|
||||
readonly VITE_API_BASE_URL?: string;
|
||||
readonly VITE_APP_BASE_PATH?: string;
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
import { defineConfig } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
|
||||
export default defineConfig({ plugins: [react()], build: { outDir: "dist" } });
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
base: process.env.VITE_APP_BASE_PATH ?? "/",
|
||||
server: {
|
||||
host: "0.0.0.0",
|
||||
port: Number(process.env.ADMIN_PORT ?? 3000),
|
||||
proxy: {
|
||||
"/api": {
|
||||
target: process.env.VITE_DEV_API_TARGET ?? "http://localhost:3001",
|
||||
rewrite: (path) => path.replace(/^\/api/, ""),
|
||||
},
|
||||
},
|
||||
},
|
||||
build: { outDir: "dist" },
|
||||
});
|
||||
@@ -458,6 +458,8 @@ export async function createApp(): Promise<NestFastifyApplication> {
|
||||
new ValidationPipe({ whitelist: true, forbidNonWhitelisted: true, transform: true }),
|
||||
);
|
||||
app.useGlobalFilters(new ApiExceptionFilter());
|
||||
const apiPrefix = process.env.API_PREFIX?.replace(/^\/+|\/+$/g, "");
|
||||
if (apiPrefix) app.setGlobalPrefix(apiPrefix);
|
||||
app.use(new RequestIdMiddleware().use.bind(new RequestIdMiddleware()));
|
||||
app.enableCors();
|
||||
return app;
|
||||
|
||||
Reference in new issue
Block a user