0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

refactor(cloud): reuse GlobalValues class from shared (#3446)

This commit is contained in:
Gao Sun 2023-03-17 15:41:12 +08:00 committed by GitHub
parent c7bbdb40a0
commit 5caa95a6eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 12 deletions

View file

@ -6,5 +6,6 @@ const config = {
coveragePathIgnorePatterns: ['/node_modules/', '/test-utils/'],
collectCoverageFrom: ['**/*.js'],
roots: ['./build'],
setupFilesAfterEnv: ['./jest.setup.js'],
};
export default config;

View file

@ -0,0 +1,7 @@
/**
* Setup environment variables for unit test
*/
process.env.DB_URL = 'postgres://mock.db.url';
process.env.ENDPOINT = 'https://logto.test';
process.env.NODE_ENV = 'test';

View file

@ -1,11 +1,4 @@
const getEnv = (key: string) => process.env[key];
class GlobalValues {
public readonly logtoEndpoint = new URL(getEnv('ADMIN_ENDPOINT') ?? 'http://localhost:3002');
public readonly dbUrl = getEnv('DB_URL');
public readonly isProduction = getEnv('NODE_ENV') === 'production';
}
import { GlobalValues } from '@logto/shared';
export const EnvSet = {
global: new GlobalValues(),

View file

@ -26,7 +26,9 @@ const { listen } = createServer({
'/api',
compose<RequestContext>()
.and(withBody())
.and(withAuth({ endpoint: EnvSet.global.logtoEndpoint, audience: cloudApiIndicator }))
.and(
withAuth({ endpoint: EnvSet.global.adminUrlSet.endpoint, audience: cloudApiIndicator })
)
.and(router.routes())
)
)

View file

@ -17,10 +17,11 @@ import {
createAdminData,
createAdminDataInAdminTenant,
} from '@logto/schemas';
import { createTenantMetadata, DemoConnector, GlobalValues } from '@logto/shared';
import { createTenantMetadata, DemoConnector } from '@logto/shared';
import type { ZodType } from 'zod';
import { z } from 'zod';
import { EnvSet } from '#src/env-set/index.js';
import { createApplicationsQueries } from '#src/queries/application.js';
import { createConnectorsQuery } from '#src/queries/connector.js';
import type { Queries } from '#src/queries/index.js';
@ -116,8 +117,7 @@ export class TenantsLibrary {
]);
// Create demo connectors
const globalValues = new GlobalValues();
const { cloudUrlSet } = globalValues;
const { cloudUrlSet } = EnvSet.global;
await Promise.all(
[DemoConnector.Email, DemoConnector.Sms].map(async (connectorId) => {