fix: pageproxy inject env in local proxy
This commit is contained in:
@@ -14,7 +14,6 @@ import cluster from 'cluster'
|
||||
import { cloneDeep, mergeWith } from 'lodash'
|
||||
import { LeanDocument } from 'mongoose'
|
||||
import { InjectModel } from 'nestjs-typegoose'
|
||||
import { API_VERSION } from '~/app.config'
|
||||
import { RedisKeys } from '~/constants/cache.constant'
|
||||
import { EventBusEvents } from '~/constants/event.constant'
|
||||
import { CacheService } from '~/processors/cache/cache.service'
|
||||
@@ -51,12 +50,10 @@ const generateDefaultConfig: () => IConfig = () => ({
|
||||
description: '哈喽~欢迎光临',
|
||||
},
|
||||
url: {
|
||||
wsUrl: 'http://127.0.0.1:2333', //todo
|
||||
adminUrl: 'http://127.0.0.1:9528',
|
||||
serverUrl: isDev
|
||||
? 'http://127.0.0.1:2333'
|
||||
: 'http://127.0.0.1:2333/api/v' + API_VERSION,
|
||||
webUrl: 'http://127.0.0.1:2323',
|
||||
wsUrl: '', //todo
|
||||
adminUrl: '',
|
||||
serverUrl: '',
|
||||
webUrl: '',
|
||||
},
|
||||
mailOptions: {} as MailOptionsDto,
|
||||
commentOptions: { antiSpam: false },
|
||||
|
||||
@@ -166,9 +166,13 @@ export class PageProxyController {
|
||||
try {
|
||||
const entry = await fs.readFile(entryPath, 'utf8')
|
||||
|
||||
const injectEnv = await this.service.injectAdminEnv(entry, {
|
||||
...(await this.service.getUrlFromConfig()),
|
||||
from: 'server',
|
||||
})
|
||||
reply
|
||||
.type('text/html')
|
||||
.send(this.service.rewriteAdminEntryAssetPath(entry))
|
||||
.send(this.service.rewriteAdminEntryAssetPath(injectEnv))
|
||||
} catch (e) {
|
||||
reply.code(500).send({
|
||||
message: e.message,
|
||||
|
||||
@@ -135,6 +135,16 @@ export class PageProxyService {
|
||||
'.json': 'application/json',
|
||||
}[ext]
|
||||
}
|
||||
|
||||
async getUrlFromConfig() {
|
||||
const config = await this.configs.waitForConfigReady()
|
||||
const url = config.url
|
||||
|
||||
return {
|
||||
BASE_API: url.serverUrl || (isDev ? '/' : '/api/v2'),
|
||||
GATEWAY: url.wsUrl || '/socket.io',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export interface IInjectableData {
|
||||
|
||||
Reference in New Issue
Block a user