Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Formula with AI #1068

Closed
wants to merge 9 commits into from
10 changes: 10 additions & 0 deletions apps/nextjs-app/src/lib/server-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ export interface IServerEnv {
socialAuthProviders?: string[];
storagePrefix?: string;
edition?: string;

// global settings
globalSettings?: {
disallowSignUp?: boolean;
disallowSpaceCreation?: boolean;
disallowSpaceInvitation?: boolean;
aiConfig?: {
enable: boolean;
};
};
}

export const EnvContext = React.createContext<IServerEnv>({});
16 changes: 16 additions & 0 deletions apps/nextjs-app/src/lib/withEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,27 @@ type GetServerSideProps<
D extends PreviewData = PreviewData,
> = (context: GetServerSidePropsContext<Q, D>) => Promise<GetServerSidePropsResult<P>>;

async function fetchPublicConfig(context?: GetServerSidePropsContext) {
try {
const protocol = process.env.NODE_ENV === 'development' ? 'http' : 'https';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use axios from apps/nextjs-app/src/backend/api/rest/axios.ts
it design to handle internal request

const host = context?.req?.headers?.host || 'localhost:3000';
const url = `${protocol}://${host}/api/admin/setting/public`;
console.log('fetchPublicConfig', url);
const response = await fetch(url);
return await response.json();
} catch (error) {
console.error('Failed to fetch public config:', error);
return {};
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export default function withEnv<P extends { [key: string]: any }>(
handler: GetServerSideProps<P, ParsedUrlQuery, PreviewData>
): NextGetServerSideProps<P> {
return async (context: GetServerSidePropsContext) => {
const { driver } = parseDsn(process.env.PRISMA_DATABASE_URL as string);
const publicConfig = await fetchPublicConfig(context);
const env = omitBy(
{
driver,
Expand All @@ -31,6 +46,7 @@ export default function withEnv<P extends { [key: string]: any }>(
sentryDsn: process.env.SENTRY_DSN,
socialAuthProviders: process.env.SOCIAL_AUTH_PROVIDERS?.split(','),
storagePrefix: process.env.STORAGE_PREFIX,
globalSettings: publicConfig,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's just ssr, it doesn't need to be defined here.

},
isUndefined
);
Expand Down