Skip to content

Commit

Permalink
apparently, prod ignores redirects or process env
Browse files Browse the repository at this point in the history
  • Loading branch information
yk committed Nov 25, 2023
1 parent 29c50ee commit ca7dc79
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 27 deletions.
24 changes: 0 additions & 24 deletions website/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,6 @@ const nextConfig = {
ignoreDuringBuilds: true,
},
async redirects() {
if (process.env.BYE === "true") {
return [
{
source: "/",
destination: "/bye",
permanent: false,
},
{
source: "/dashboard",
destination: "/bye",
permanent: false,
},
{
source: "/chat",
destination: "/bye",
permanent: false,
},
{
source: "/contributors",
destination: "https://ykilcher.com/oa-contributors",
permanent: false,
},
];
}
if (process.env.MAINTENANCE_MODE !== "true") {
return [];
}
Expand Down
1 change: 1 addition & 0 deletions website/src/hooks/env/BrowserEnv.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createContext, useContext } from "react";

export interface BrowserConfig {
BYE: boolean;
ENABLE_CHAT: boolean;
ENABLE_DRAFTS_WITH_PLUGINS: boolean;
NUM_GENERATED_DRAFTS: number;
Expand Down
1 change: 1 addition & 0 deletions website/src/pages/api/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { BrowserConfig } from "src/types/Config";

// don't put sensitive information here
const config: BrowserConfig = {
BYE: boolean(process.env.BYE),
ENABLE_CHAT: boolean(process.env.ENABLE_CHAT),
ENABLE_DRAFTS_WITH_PLUGINS: boolean(process.env.ENABLE_DRAFTS_WITH_PLUGINS),
NUM_GENERATED_DRAFTS: Number(process.env.NUM_GENERATED_DRAFTS),
Expand Down
3 changes: 2 additions & 1 deletion website/src/pages/bye.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Image from "next/image";
import Link from "next/link";
import { Container } from "src/components/Container";
export { getStaticProps } from "src/lib/defaultServerSideProps";

Expand All @@ -20,7 +21,7 @@ const ByePage = () => {
<h2 className="text-2xl font-bold mt-4 mb-2">Links:</h2>
<ul className="text-2xl list-none text-blue-500">
<li>
<a href="/contributors">List of contributors</a>
<Link href="/contributors">List of contributors</Link>
</li>
<li>
<a href="https://ykilcher.com/oa-paper">Paper</a>
Expand Down
10 changes: 9 additions & 1 deletion website/src/pages/chat/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import { get } from "src/lib/api";
import { ModelInfo, PluginEntry } from "src/types/Chat";
export { getServerSideProps } from "src/lib/defaultServerSideProps";
import useSWRImmutable from "swr/immutable";
import { useBrowserConfig } from "src/hooks/env/BrowserEnv";

const Chat = () => {
const { query } = useRouter();
const { BYE } = useBrowserConfig();
const router = useRouter();
const { query } = router;
const id = query.id as string;
const { t } = useTranslation(["common", "chat"]);
const { data: modelInfos } = useSWRImmutable<ModelInfo[]>("/api/chat/models", get, {
Expand All @@ -20,6 +23,11 @@ const Chat = () => {
keepPreviousData: true,
});

if (BYE) {
router.push("/bye");
return null;
}

return (
<>
<Head>
Expand Down
9 changes: 9 additions & 0 deletions website/src/pages/contributors.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useRouter } from "next/router";

const ContributorsPage = () => {
const router = useRouter();
router.push("https://ykilcher.com/oa-contributors");
return null;
};

export default ContributorsPage;
9 changes: 8 additions & 1 deletion website/src/pages/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import { useBrowserConfig } from "src/hooks/env/BrowserEnv";
import { useCurrentLocale } from "src/hooks/locale/useCurrentLocale";
import { API_ROUTES } from "src/lib/routes";
import useSWR from "swr";
import { useRouter } from "next/router";

const Dashboard = () => {
const { t } = useTranslation(["dashboard", "common", "tasks"]);
const { ENABLE_CHAT } = useBrowserConfig();
const { ENABLE_CHAT, BYE } = useBrowserConfig();
const router = useRouter();
const lang = useCurrentLocale();
const { data } = useSWR<AvailableTasks>(API_ROUTES.AVAILABLE_TASK({ lang }), get, {
refreshInterval: 2 * 60 * 1000, //2 minutes
Expand Down Expand Up @@ -55,6 +57,11 @@ const Dashboard = () => {
},
};

if (BYE) {
router.push("/bye");
return null;
}

return (
<>
<Head>
Expand Down
7 changes: 7 additions & 0 deletions website/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import { CallToAction } from "src/components/CallToAction";
import { Faq } from "src/components/Faq";
import { Hero } from "src/components/Hero";
export { getDefaultServerSideProps as getStaticProps } from "src/lib/defaultServerSideProps";
import { useBrowserConfig } from "src/hooks/env/BrowserEnv";

const Home = () => {
const { BYE } = useBrowserConfig();
const router = useRouter();
const { status } = useSession();
const { t } = useTranslation();
Expand All @@ -19,6 +21,11 @@ const Home = () => {
}
}, [router, status]);

if (BYE) {
router.push("/bye");
return null;
}

return (
<>
<Head>
Expand Down
1 change: 1 addition & 0 deletions website/src/types/Config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface BrowserConfig {
BYE: boolean;
ENABLE_CHAT: boolean;
ENABLE_DRAFTS_WITH_PLUGINS: boolean; // Whether draft messages should be generated if plugins are in use
NUM_GENERATED_DRAFTS: number;
Expand Down
1 change: 1 addition & 0 deletions website/types/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ declare global {
ADMIN_USERS: string;
MODERATOR_USERS: string;
INFERENCE_SERVER_HOST: string;
BYE: boolean;
ENABLE_CHAT: boolean;
ENABLE_DRAFTS_WITH_PLUGINS: boolean;
NUM_GENERATED_DRAFTS: number;
Expand Down

0 comments on commit ca7dc79

Please sign in to comment.