import { defineConfig } from 'vite'
import basicSsl from '@vitejs/plugin-basic-ssl'
import { readFileSync, existsSync } from 'fs'
import { resolve } from 'path'
import os from 'os'

export default defineConfig({
  plugins: [basicSsl({
    // Use custom certificates if available
    name: 'localhost',
    domains: ['localhost', '127.0.0.1'],
    certDir: resolve(os.tmpdir(), 'spa-entra-id-certs') // Use OS temp dir for certs
  })],
  server: {
    port: 5001,
    host: 'localhost',
    strictPort: true, // Only run on port 5001
    open: false // Don't auto-open to avoid cert warnings
  },
  build: {
    outDir: 'dist',
    rollupOptions: {
      input: {
        main: 'index.html',
        auth: 'auth.html'
      }
    }
  }
})
