import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
//import vueDevTools from 'vite-plugin-vue-devtools'
import fs from 'fs'

export default defineConfig({
  plugins: [vue() /*vueDevTools()*/],
  server: {
    host: '0.0.0.0',
    https: {
      key: fs.readFileSync('./192.168.1.102+1-key.pem'),
      cert: fs.readFileSync('./192.168.1.102+1.pem'),
    },
    proxy: {
      '/api': {
        target: 'http://192.168.1.102:5000',
        changeOrigin: true,
        rewrite: (p) => p.replace(/^\/api/, ''),
      },
      '/events': {
        target: 'http://192.168.1.102:5000',
        changeOrigin: true,
        secure: false,
      },
    },
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
})
