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:
parent
c7bbdb40a0
commit
5caa95a6eb
5 changed files with 15 additions and 12 deletions
|
@ -6,5 +6,6 @@ const config = {
|
|||
coveragePathIgnorePatterns: ['/node_modules/', '/test-utils/'],
|
||||
collectCoverageFrom: ['**/*.js'],
|
||||
roots: ['./build'],
|
||||
setupFilesAfterEnv: ['./jest.setup.js'],
|
||||
};
|
||||
export default config;
|
||||
|
|
7
packages/cloud/jest.setup.js
Normal file
7
packages/cloud/jest.setup.js
Normal 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';
|
|
@ -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(),
|
||||
|
|
|
@ -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())
|
||||
)
|
||||
)
|
||||
|
|
|
@ -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) => {
|
||||
|
|
Loading…
Reference in a new issue