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