mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
refactor: read issuer from env and fallback to localhost
This commit is contained in:
parent
3e58d991d8
commit
8c95b5d856
4 changed files with 11 additions and 9 deletions
|
@ -1,4 +1,4 @@
|
|||
import { assertEnv } from '@/utils/env';
|
||||
import { assertEnv, getEnv } from '@/utils/env';
|
||||
|
||||
const signIn = assertEnv('UI_SIGN_IN_ROUTE');
|
||||
|
||||
|
@ -8,3 +8,6 @@ export const routes = Object.freeze({
|
|||
consent: signIn + '/consent',
|
||||
},
|
||||
});
|
||||
|
||||
export const port = Number(getEnv('PORT', '3001'));
|
||||
export const oidcIssuer = getEnv('OIDC_ISSUER', `http://localhost:${port}/oidc`);
|
||||
|
|
|
@ -5,14 +5,12 @@ dotenv.config();
|
|||
|
||||
import Koa from 'koa';
|
||||
import initApp from './init';
|
||||
import { getEnv } from './utils/env';
|
||||
|
||||
const app = new Koa();
|
||||
const port = Number(getEnv('PORT', '3001'));
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await initApp(app, port);
|
||||
await initApp(app);
|
||||
} catch (error: unknown) {
|
||||
console.log('Error while initializing app', error);
|
||||
}
|
||||
|
|
|
@ -4,12 +4,13 @@ import koaLogger from 'koa-logger';
|
|||
import koaErrorHandler from '@/middleware/koa-error-handler';
|
||||
import initOidc from './oidc';
|
||||
import initRouter from './router';
|
||||
import { port } from '@/consts';
|
||||
|
||||
export default async function initApp(app: Koa, port: number): Promise<void> {
|
||||
export default async function initApp(app: Koa): Promise<void> {
|
||||
app.use(koaErrorHandler());
|
||||
app.use(koaLogger());
|
||||
|
||||
const provider = await initOidc(app, port);
|
||||
const provider = await initOidc(app);
|
||||
initRouter(app, provider);
|
||||
|
||||
app.listen(port, () => {
|
||||
|
|
|
@ -7,9 +7,9 @@ import postgresAdapter from '@/oidc/adapter';
|
|||
import { fromKeyLike } from 'jose/jwk/from_key_like';
|
||||
import { getEnv } from '@/utils/env';
|
||||
import { findUserById } from '@/queries/user';
|
||||
import { routes } from '@/consts';
|
||||
import { oidcIssuer, routes } from '@/consts';
|
||||
|
||||
export default async function initOidc(app: Koa, port: number): Promise<Provider> {
|
||||
export default async function initOidc(app: Koa): Promise<Provider> {
|
||||
const privateKey = crypto.createPrivateKey(
|
||||
Buffer.from(getEnv('OIDC_PROVIDER_PRIVATE_KEY_BASE64'), 'base64')
|
||||
);
|
||||
|
@ -19,7 +19,7 @@ export default async function initOidc(app: Koa, port: number): Promise<Provider
|
|||
path: '/',
|
||||
signed: true,
|
||||
} as const);
|
||||
const oidc = new Provider(`http://localhost:${port}/oidc`, {
|
||||
const oidc = new Provider(oidcIssuer, {
|
||||
adapter: postgresAdapter,
|
||||
renderError: (ctx, out, error) => {
|
||||
console.log('OIDC error', error);
|
||||
|
|
Loading…
Reference in a new issue