This commit is contained in:
parent
cf72a2c302
commit
330af05144
|
|
@ -42,7 +42,7 @@ export async function startup<ED extends EntityDict & BaseEntityDict, FrontCxt e
|
|||
omitWatchers?: boolean,
|
||||
omitTimers?: boolean,
|
||||
routine?: (context: AsyncContext<ED>) => Promise<void>,
|
||||
): Promise<(() => Promise<void>) | undefined> {
|
||||
): Promise<(() => Promise<void> )| undefined> {
|
||||
const serverConfiguration: ServerConfiguration = require(join(
|
||||
path,
|
||||
'lib',
|
||||
|
|
@ -68,11 +68,11 @@ export async function startup<ED extends EntityDict & BaseEntityDict, FrontCxt e
|
|||
const socketOption: Partial<ServerOptions> = {
|
||||
path: connector.getSocketPath(),
|
||||
cors: ['development', 'staging'].includes(process.env.NODE_ENV!)
|
||||
? {
|
||||
origin: '*',
|
||||
allowedHeaders: corsHeaders.concat(connector.getCorsHeader()),
|
||||
}
|
||||
: serverConfiguration.cors
|
||||
? {
|
||||
origin: '*',
|
||||
allowedHeaders: corsHeaders.concat(connector.getCorsHeader()),
|
||||
}
|
||||
: serverConfiguration.cors
|
||||
? {
|
||||
origin: serverConfiguration.cors.origin, //socket.io配置cors origin是支持数组和字符串
|
||||
allowedHeaders: [
|
||||
|
|
@ -102,15 +102,15 @@ export async function startup<ED extends EntityDict & BaseEntityDict, FrontCxt e
|
|||
}
|
||||
const isCluster = Array.isArray(redisConfig);
|
||||
// 创建 Redis 客户端
|
||||
const pubClient = isCluster ?
|
||||
const pubClient = isCluster ?
|
||||
new Redis.Cluster(redisConfig.map((config) => ({
|
||||
...config,
|
||||
lazyConnect: true,
|
||||
})))
|
||||
: new Redis({
|
||||
...redisConfig,
|
||||
lazyConnect: true,
|
||||
});
|
||||
: new Redis({
|
||||
...redisConfig,
|
||||
lazyConnect: true,
|
||||
});
|
||||
const subClient = pubClient.duplicate();
|
||||
pubClient.on('connect', () => {
|
||||
console.log('PUB已成功连接到Redis服务器');
|
||||
|
|
@ -156,7 +156,7 @@ export async function startup<ED extends EntityDict & BaseEntityDict, FrontCxt e
|
|||
const appLoader = clusterInfo.usingCluster
|
||||
? new ClusterAppLoader<ED, Cxt>(
|
||||
path,
|
||||
io.of(DATA_SUBSCRIBE_NAMESPACE),
|
||||
io.of(DATA_SUBSCRIBE_NAMESPACE ),
|
||||
io.of(SOCKET_NAMESPACE),
|
||||
io.of(SERVER_SUBSCRIBER_NAMESPACE),
|
||||
connector.getSocketPath()
|
||||
|
|
@ -329,10 +329,14 @@ export async function startup<ED extends EntityDict & BaseEntityDict, FrontCxt e
|
|||
|
||||
// 注入所有的endpoints
|
||||
const endpoints = appLoader.getEndpoints(connector.getEndpointRouter());
|
||||
endpoints.forEach(([type, name, method, url, fn]) => {
|
||||
endpoints.forEach(([name, method, url, fn]) => {
|
||||
router[method](url, async (ctx) => {
|
||||
const { req, request, params } = ctx;
|
||||
const { body, headers, files } = request;
|
||||
try {
|
||||
await fn(ctx);
|
||||
const result = await fn(params, headers, req, files ? Object.assign({}, body, files) : body);
|
||||
ctx.response.body = result;
|
||||
return;
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue