remove DOMAIN env, initial fit fetching in /unity
This commit is contained in:
parent
7fb8601dd3
commit
de6bdf6aa0
3
.env
3
.env
|
|
@ -1,2 +1 @@
|
||||||
# placing my env here
|
# placing my env here
|
||||||
DOMAIN=http://localhost:3000
|
|
||||||
|
|
@ -1,2 +1 @@
|
||||||
# placing my env here
|
# placing my env here
|
||||||
DOMAIN=https://nextjs-test-rnd.vercel.app
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { NextRequest } from "next/server";
|
import { NextRequest } from "next/server";
|
||||||
import { frame, ohg } from "../constant";
|
import { frame, ohg } from "../constant";
|
||||||
|
import { LengthType } from "../types";
|
||||||
|
|
||||||
export async function GET(request: NextRequest) {
|
export async function GET(request: NextRequest) {
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
|
|
@ -17,8 +18,8 @@ export async function GET(request: NextRequest) {
|
||||||
(Object.keys(frameObject.length).reduce(
|
(Object.keys(frameObject.length).reduce(
|
||||||
(prev, curr) =>
|
(prev, curr) =>
|
||||||
prev +
|
prev +
|
||||||
(ohgObject.length[curr as keyof typeof ohgObject.length] -
|
(ohgObject.length[curr as keyof LengthType] -
|
||||||
frameObject.length[curr as keyof typeof frameObject.length]) **
|
frameObject.length[curr as keyof LengthType]) **
|
||||||
2,
|
2,
|
||||||
0,
|
0,
|
||||||
) /
|
) /
|
||||||
|
|
|
||||||
|
|
@ -6,25 +6,12 @@ const getItem = async () => {
|
||||||
return await Promise.resolve({ option, ohg, frame });
|
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() {
|
export default async function UnityComponent() {
|
||||||
const { option, ohg, frame } = await getItem();
|
const { option, ohg, frame } = await getItem();
|
||||||
const res = await getInitMatch();
|
|
||||||
const initMatch = (await res.json()) as { match: number };
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Suspense>
|
<Suspense>
|
||||||
<Unity
|
<Unity option={option} ohg={ohg} frame={frame} />
|
||||||
option={option}
|
|
||||||
ohg={ohg}
|
|
||||||
frame={frame}
|
|
||||||
initMatch={initMatch?.match ?? 0}
|
|
||||||
/>
|
|
||||||
</Suspense>
|
</Suspense>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ const unityConfigBuilder: (path: string) => UnityConfig = (path) => ({
|
||||||
});
|
});
|
||||||
|
|
||||||
export default function UnityComponent({
|
export default function UnityComponent({
|
||||||
initMatch,
|
|
||||||
option = [],
|
option = [],
|
||||||
ohg = [],
|
ohg = [],
|
||||||
frame = [],
|
frame = [],
|
||||||
|
|
@ -28,12 +27,11 @@ export default function UnityComponent({
|
||||||
}[];
|
}[];
|
||||||
ohg: ObjectType[];
|
ohg: ObjectType[];
|
||||||
frame: ObjectType[];
|
frame: ObjectType[];
|
||||||
initMatch: number;
|
|
||||||
}) {
|
}) {
|
||||||
const params = useSearchParams();
|
const params = useSearchParams();
|
||||||
const p = params.get("p");
|
const p = params.get("p");
|
||||||
const [selectedIndex, setSelectedIndex] = useState({ ohg: 0, frame: 0 });
|
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";
|
if (!p || isNaN(Number(p))) location.href = "/unity?p=0";
|
||||||
|
|
||||||
const { unityProvider, isLoaded, loadingProgression, UNSAFE__unityInstance } =
|
const { unityProvider, isLoaded, loadingProgression, UNSAFE__unityInstance } =
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue