remove DOMAIN env, initial fit fetching in /unity

This commit is contained in:
sjwie 2024-05-03 15:35:35 +09:00
parent 7fb8601dd3
commit de6bdf6aa0
5 changed files with 7 additions and 23 deletions

1
.env
View File

@ -1,2 +1 @@
# placing my env here
DOMAIN=http://localhost:3000

View File

@ -1,2 +1 @@
# placing my env here
DOMAIN=https://nextjs-test-rnd.vercel.app

View File

@ -1,5 +1,6 @@
import { NextRequest } from "next/server";
import { frame, ohg } from "../constant";
import { LengthType } from "../types";
export async function GET(request: NextRequest) {
const { searchParams } = new URL(request.url);
@ -17,8 +18,8 @@ export async function GET(request: NextRequest) {
(Object.keys(frameObject.length).reduce(
(prev, curr) =>
prev +
(ohgObject.length[curr as keyof typeof ohgObject.length] -
frameObject.length[curr as keyof typeof frameObject.length]) **
(ohgObject.length[curr as keyof LengthType] -
frameObject.length[curr as keyof LengthType]) **
2,
0,
) /

View File

@ -6,25 +6,12 @@ const getItem = async () => {
return await Promise.resolve({ option, ohg, frame });
};
const getInitMatch = async () => {
return await fetch(`${process.env.DOMAIN}/fit?o=0&f=0`, {
method: "GET",
});
};
export default async function UnityComponent() {
const { option, ohg, frame } = await getItem();
const res = await getInitMatch();
const initMatch = (await res.json()) as { match: number };
return (
<Suspense>
<Unity
option={option}
ohg={ohg}
frame={frame}
initMatch={initMatch?.match ?? 0}
/>
<Unity option={option} ohg={ohg} frame={frame} />
</Suspense>
);
}

View File

@ -16,7 +16,6 @@ const unityConfigBuilder: (path: string) => UnityConfig = (path) => ({
});
export default function UnityComponent({
initMatch,
option = [],
ohg = [],
frame = [],
@ -28,12 +27,11 @@ export default function UnityComponent({
}[];
ohg: ObjectType[];
frame: ObjectType[];
initMatch: number;
}) {
const params = useSearchParams();
const p = params.get("p");
const [selectedIndex, setSelectedIndex] = useState({ ohg: 0, frame: 0 });
const [match, setMatch] = useState(initMatch);
const [match, setMatch] = useState(100);
if (!p || isNaN(Number(p))) location.href = "/unity?p=0";
const { unityProvider, isLoaded, loadingProgression, UNSAFE__unityInstance } =