import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react-swc';
import { VitePWA } from 'vite-plugin-pwa';

export default defineConfig({
  server: {
    host: "0.0.0.0",
    port: 3000, // You can use any port
    proxy: {
      // This proxies API calls to your backend during development to bypass CORS
      '/api': {
        target: 'https://rexplorerapi.azurewebsites.net/', // Replace this with your API base URL
        changeOrigin: true, // Needed for virtual hosted sites
        secure: false, // If your API is HTTPS and you're not using a certificate, this can be false
        rewrite: (path) => path.replace(/^\/api/, ''), // Removes '/api' prefix when forwarding to the server
      },
    },
  },
  plugins: [
    react(),
    VitePWA({
      registerType: "autoUpdate",
      devOptions: {
        enabled: true,
      },
      manifest: {
        "theme_color": "#150a29",
        "background_color": "#150a29",
        "icons": [
          {
            "purpose": "maskable",
            "sizes": "512x512",
            "src": "icon512_maskable.png",
            "type": "image/png"
          },
          {
            "purpose": "any",
            "sizes": "512x512",
            "src": "icon512_rounded.png",
            "type": "image/png"
          }
        ],
        "orientation": "any",
        "display": "standalone",
        "dir": "auto",
        "lang": "en-US",
        "name": "Rubix"
      },
    }),
  ],
});
