fix: pageproxy inject env in local proxy

This commit is contained in:
Innei
2022-02-25 12:14:51 +08:00
parent 8cf0f56da6
commit 130f6f0d2f
3 changed files with 19 additions and 8 deletions

View File

@@ -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 },

View File

@@ -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,

View File

@@ -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 {