import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";

export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src"),
    },
  },
  server: {
    proxy: {
      "/api": {
        target: "http://localhost:8080",
        changeOrigin: true, // 允许跨域
        rewrite: (path) => path.replace(/^\/api/, ""), 
      },
      "/proxy": {
        target: "http://localhost:3000", 
        changeOrigin: true, 
      },
      "/online": {
        target: "ws://localhost:8080",
        changeOrigin: true,
        ws: true,
      },
      "/voice": {
        target: "ws://localhost:8080",
        changeOrigin: true,
        ws: true,
      },
      "/vditor": {
        target: "http://localhost:5173",
        rewrite: (path) => {
          return path.replace(/^\/vditor/, "/node_modules/vditor");
        },
      },
    },
    host: "0.0.0.0",
  },
  // server: {
  //   https:{
  //     key: fs.readFileSync('./cert/merlin.xin.key'),
  //     cert: fs.readFileSync('./cert/merlin.xin.pem'),
  //   },
  //   proxy: {
  //     '/api': {
  //       target: 'https://localhost:8443', // 后端服务器地址
  //       changeOrigin: true, // 允许跨域
  //       rewrite: (path) => path.replace(/^\/api/, ''), // 重写路径，去掉 /api 前缀
  //     },
  //     '/online':{
  //       target:'wss://localhost:8443/online',
  //       changeOrigin:true,
  //       ws:true,
  //     },
  //     '/voice':{
  //       target:'wss://localhost:8443/voice',
  //       changeOrigin:true,
  //       ws:true,
  //     }
  //   },
  // },
});
