restructure some constants

This commit is contained in:
Evert Prants 2022-09-11 12:44:43 +03:00
parent 3da302e35f
commit 8a1d12a218
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
5 changed files with 8 additions and 6 deletions

View File

@ -1,7 +1,8 @@
export const PUBLIC_URL = process.env.NEXT_PUBLIC_URL as string;
export const SERVER_URL = process.env.SERVER_URL as string;
export const API_URL = `${SERVER_URL}/api`;
export const OAUTH_URL = `${SERVER_URL}/oauth2`;
export const AUTHORIZE_URL = process.env.AUTHORIZE_URL as string;
export const TOKEN_URL = process.env.TOKEN_URL as string;
export const REDIRECT_URL = `${PUBLIC_URL}/api/callback`;
export const CLIENT_ID = process.env.CLIENT_ID as string;
export const CLIENT_SECRET = process.env.CLIENT_SECRET as string;

View File

@ -1,4 +1,4 @@
import { API_URL, CLIENT_ID, CLIENT_SECRET, OAUTH_URL } from '../constants';
import { CLIENT_ID, CLIENT_SECRET, TOKEN_URL } from '../constants';
import { OAuth2TokenDto } from '../types/token-response.interface';
export async function fetchBearer<T>(
@ -16,7 +16,7 @@ export async function fetchBearer<T>(
}
export async function fetchToken(code: string): Promise<OAuth2TokenDto> {
return fetch(`${OAUTH_URL}/token`, {
return fetch(TOKEN_URL, {
headers: {
Authorization: `Basic ${Buffer.from(
`${CLIENT_ID}:${CLIENT_SECRET}`

View File

@ -3,7 +3,7 @@ const nextConfig = {
reactStrictMode: true,
swcMinify: true,
images: {
domains: ['localhost', '127.0.0.1', 'icynet.eu'],
domains: ['localhost', '127.0.0.1', 'secure.icynet.eu'],
},
};

View File

@ -1,9 +1,9 @@
import Cookies from 'cookies';
import { NextApiRequest, NextApiResponse } from 'next';
import {
AUTHORIZE_URL,
CLIENT_ID,
COOKIE_KEYS,
OAUTH_URL,
REDIRECT_URL,
} from '../../lib/constants';
import { encrypt, generateString } from '../../lib/utils/crypto';
@ -34,5 +34,5 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
signed: true,
});
res.redirect(`${OAUTH_URL}/authorize?${params.toString()}`);
res.redirect(`${AUTHORIZE_URL}?${params.toString()}`);
}

View File

@ -5,6 +5,7 @@ export const proxy = httpProxy.createProxyServer({
* Get the actual back-end service url from env variables.
* We shouldn't prefix the env variable with NEXT_PUBLIC_* to avoid exposing it to the client.
*/
changeOrigin: process.env.NODE_ENV === 'production',
target: process.env.SERVER_URL,
autoRewrite: false,
});