import { defineConfig, type Plugin } from 'vite'
import react from '@vitejs/plugin-react'

function adminRootRedirect(): Plugin {
  return {
    name: 'admin-root-redirect',
    configureServer(server) {
      server.middlewares.use((request, response, next) => {
        if (request.url === '/') {
          response.statusCode = 302
          response.setHeader('Location', '/admin.html')
          response.end()
          return
        }
        next()
      })
    },
  }
}

export default defineConfig({
  build: {
    outDir: 'dist-admin',
    rollupOptions: {
      input: 'admin.html',
    },
  },
  plugins: [react(), adminRootRedirect()],
})
