vite.config
This commit is contained in:
parent
b66c4a4aa7
commit
dea51d66ba
2 changed files with 13 additions and 3 deletions
|
|
@ -1,6 +1,7 @@
|
|||
// scripts/tenant.ts
|
||||
import axios from 'axios'
|
||||
import https from 'https'
|
||||
import fs from 'fs'
|
||||
|
||||
export type TenantDto = { name: string }
|
||||
export type PagedResultDto<T> = { totalCount: number; items: T[] }
|
||||
|
|
@ -10,12 +11,15 @@ export async function fetchTenantNames(apiUrl: string): Promise<string[]> {
|
|||
const url = `${apiUrl.replace(/\/$/, '')}/api/app/platform-tenant?skipCount=0&maxResultCount=1000`
|
||||
const isLocalHttps = /^https:\/\/localhost(:\d+)?/i.test(apiUrl)
|
||||
|
||||
const ca = fs.readFileSync('/etc/ssl/sozsoft/cert1.pem')
|
||||
const agent = new https.Agent({ ca })
|
||||
|
||||
const response = await axios.get<PagedResultDto<TenantDto>>(url, {
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
},
|
||||
httpsAgent: isLocalHttps ? new https.Agent({ rejectUnauthorized: false }) : undefined,
|
||||
httpsAgent: isLocalHttps ? new https.Agent({ rejectUnauthorized: false }) : agent,
|
||||
})
|
||||
|
||||
return (response.data.items ?? []).map((t: TenantDto) => t.name.trim().toLowerCase())
|
||||
|
|
|
|||
|
|
@ -6,12 +6,18 @@ import { VitePWA } from 'vite-plugin-pwa'
|
|||
import { fetchTenantNames } from './src/services/tenants'
|
||||
|
||||
export default defineConfig(async ({ mode }) => {
|
||||
const baseDomains = ['sozsoft.com', 'dev.sozsoft.com']
|
||||
const env = loadEnv(mode, process.cwd(), '')
|
||||
const apiUrl = env.VITE_API_URL
|
||||
const tenantNames = await fetchTenantNames(apiUrl)
|
||||
const baseDomains = ['sozsoft.com', 'dev.sozsoft.com']
|
||||
const tenantNames = (await fetchTenantNames(apiUrl)).map((n) => n.trim().toLowerCase())
|
||||
const tenantHosts = tenantNames.flatMap((t) => baseDomains.map((d) => `${t}.${d}`))
|
||||
const allowedHosts = Array.from(new Set(['localhost', ...baseDomains, ...tenantHosts]))
|
||||
|
||||
console.log('[vite] env:', env)
|
||||
console.log('[vite] url:', apiUrl)
|
||||
console.log('[vite] tenants:', tenantNames)
|
||||
console.log('[vite] allowedHosts:', allowedHosts)
|
||||
|
||||
return {
|
||||
plugins: [
|
||||
react({
|
||||
|
|
|
|||
Loading…
Reference in a new issue