mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
Refactor getConfig calls
This commit is contained in:
@@ -11,8 +11,7 @@ export default async function AppLayout({
|
|||||||
}: {
|
}: {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}) {
|
}) {
|
||||||
const hostname = new URL(process.env.NEXT_PUBLIC_SITE_URL!).hostname;
|
const config = await getConfig();
|
||||||
const config = await getConfig(hostname);
|
|
||||||
const { requireLogin, privacy, browse, rooms } = config.features;
|
const { requireLogin, privacy, browse, rooms } = config.features;
|
||||||
return (
|
return (
|
||||||
<Container
|
<Container
|
||||||
|
|||||||
@@ -66,8 +66,7 @@ export default async function RootLayout({
|
|||||||
}: {
|
}: {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}) {
|
}) {
|
||||||
const hostname = new URL(process.env.NEXT_PUBLIC_SITE_URL!).hostname;
|
const config = await getConfig();
|
||||||
const config = await getConfig(hostname);
|
|
||||||
const hasAuthCookie = !!cookies().get(SESSION_COOKIE_NAME);
|
const hasAuthCookie = !!cookies().get(SESSION_COOKIE_NAME);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ export function edgeDomainToKey(domain: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get edge config server-side (prefer DomainContext when available), domain is the hostname
|
// get edge config server-side (prefer DomainContext when available), domain is the hostname
|
||||||
export async function getConfig(domain: string) {
|
export async function getConfig() {
|
||||||
|
const domain = new URL(process.env.NEXT_PUBLIC_SITE_URL!).hostname;
|
||||||
|
|
||||||
if (process.env.NEXT_PUBLIC_ENV === "development") {
|
if (process.env.NEXT_PUBLIC_ENV === "development") {
|
||||||
return require("../../config").localConfig;
|
return require("../../config").localConfig;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export const getFiefAuth = async (url: URL) => {
|
|||||||
if (FIEF_AUTHS[url.hostname]) {
|
if (FIEF_AUTHS[url.hostname]) {
|
||||||
return FIEF_AUTHS[url.hostname];
|
return FIEF_AUTHS[url.hostname];
|
||||||
} else {
|
} else {
|
||||||
const config = url && (await getConfig(url.hostname));
|
const config = url && (await getConfig());
|
||||||
if (config) {
|
if (config) {
|
||||||
FIEF_AUTHS[url.hostname] = new FiefAuth({
|
FIEF_AUTHS[url.hostname] = new FiefAuth({
|
||||||
client: fiefClient,
|
client: fiefClient,
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ import { getFiefAuthMiddleware } from "./app/lib/fief";
|
|||||||
import { getConfig } from "./app/lib/edgeConfig";
|
import { getConfig } from "./app/lib/edgeConfig";
|
||||||
|
|
||||||
export async function middleware(request: NextRequest) {
|
export async function middleware(request: NextRequest) {
|
||||||
const hostname = new URL(process.env.NEXT_PUBLIC_SITE_URL!).hostname;
|
const config = await getConfig();
|
||||||
const config = await getConfig(hostname);
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
request.nextUrl.pathname.match(
|
request.nextUrl.pathname.match(
|
||||||
|
|||||||
@@ -3,9 +3,8 @@ import { URLSearchParams } from "url";
|
|||||||
import { getConfig } from "../../app/lib/edgeConfig";
|
import { getConfig } from "../../app/lib/edgeConfig";
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
const domainName = req.headers.host;
|
const config = await getConfig();
|
||||||
const config = await getConfig(domainName);
|
const { sendToZulip } = config.features;
|
||||||
const { requireLogin, privacy, browse, sendToZulip } = config.features;
|
|
||||||
|
|
||||||
if (req.method === "POST") {
|
if (req.method === "POST") {
|
||||||
const { stream, topic, message } = req.body;
|
const { stream, topic, message } = req.body;
|
||||||
|
|||||||
Reference in New Issue
Block a user