summaryrefslogtreecommitdiffhomepage
path: root/vite.config.ts
blob: 80a4102e03a9186052d41b576d0961521d757a0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import tailwindcss from '@tailwindcss/vite'
import fs from 'fs'

const port = parseInt(process.env.VITE_PORT || '5188')
const apiPort = process.env.VITE_API_PORT || '3100'
const host = process.env.VITE_HOST || 'arch-razer.chimera-dinosaur.ts.net'

const certPath = 'tmp/tls/cert.pem'
const keyPath = 'tmp/tls/key.pem'
const hasCerts = fs.existsSync(certPath) && fs.existsSync(keyPath)

// https://vite.dev/config/
export default defineConfig({
  plugins: [tailwindcss(), svelte()],
  server: {
    port,
    host: '0.0.0.0',
    ...(hasCerts
      ? {
          https: {
            cert: fs.readFileSync(certPath),
            key: fs.readFileSync(keyPath),
          },
        }
      : {}),
    proxy: {
      '/api': {
        target: `https://${host}:${apiPort}`,
        changeOrigin: true,
        secure: false,
      },
      '/cable': {
        target: `wss://${host}:${apiPort}`,
        ws: true,
        secure: false,
      },
    },
  },
})