feat: update environment configuration, enhance Dockerfiles, and refactor API handling
This commit is contained in:
@@ -1,30 +1,27 @@
|
||||
FROM oven/bun:1 AS base
|
||||
FROM node:22-slim AS builder
|
||||
WORKDIR /app
|
||||
|
||||
FROM base AS install
|
||||
RUN mkdir -p /temp/dev
|
||||
COPY package.json bun.lock /temp/dev/
|
||||
RUN cd /temp/dev && bun install --frozen-lockfile
|
||||
ARG NEXT_PUBLIC_API_URL
|
||||
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
|
||||
|
||||
RUN mkdir -p /temp/prod
|
||||
COPY package.json bun.lock /temp/prod/
|
||||
RUN cd /temp/prod && bun install --frozen-lockfile --production
|
||||
# Install dependencies with Bun for speed
|
||||
COPY --chown=node:node package.json bun.lock ./
|
||||
RUN npm install -g bun
|
||||
RUN bun install --frozen-lockfile
|
||||
|
||||
FROM base AS prerelease
|
||||
COPY --from=install /temp/dev/node_modules node_modules
|
||||
COPY . .
|
||||
# Copy the rest of the app and build with Node's Next.js runtime
|
||||
COPY --chown=node:node . .
|
||||
|
||||
ENV NODE_ENV=production
|
||||
RUN bun run build
|
||||
|
||||
FROM base AS release
|
||||
FROM node:22-slim AS release
|
||||
|
||||
COPY --from=prerelease /app/public ./public
|
||||
COPY --from=prerelease /app/.next/standalone ./
|
||||
COPY --from=prerelease /app/.next/static ./.next/static
|
||||
COPY --from=builder /app/public ./public
|
||||
COPY --from=builder /app/.next/standalone ./
|
||||
COPY --from=builder /app/.next/static ./.next/static
|
||||
|
||||
USER bun
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["bun", "run", "server.js"]
|
||||
CMD ["node", "server.js"]
|
||||
|
||||
|
@@ -14,7 +14,6 @@ import { PopularTags } from "@/components/popular-tags";
|
||||
import { ThoughtThread } from "@/components/thought-thread";
|
||||
import { buildThoughtThreads } from "@/lib/utils";
|
||||
import { TopFriends } from "@/components/top-friends";
|
||||
import InstallPrompt from "@/components/install-prompt";
|
||||
|
||||
export default async function Home() {
|
||||
const token = (await cookies()).get("auth_token")?.value ?? null;
|
||||
|
@@ -111,7 +111,10 @@ export type ApiKey = z.infer<typeof ApiKeySchema>;
|
||||
export type ApiKeyResponse = z.infer<typeof ApiKeyResponseSchema>;
|
||||
export type ThoughtThread = z.infer<typeof ThoughtThreadSchema>;
|
||||
|
||||
const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8000";
|
||||
const API_BASE_URL =
|
||||
typeof window === "undefined"
|
||||
? process.env.NEXT_PUBLIC_SERVER_SIDE_API_URL // Server-side
|
||||
: process.env.NEXT_PUBLIC_API_URL; // Client-side
|
||||
|
||||
async function apiFetch<T>(
|
||||
endpoint: string,
|
||||
@@ -119,6 +122,10 @@ async function apiFetch<T>(
|
||||
schema: z.ZodType<T>,
|
||||
token?: string | null
|
||||
): Promise<T> {
|
||||
if (!API_BASE_URL) {
|
||||
throw new Error("API_BASE_URL is not defined");
|
||||
}
|
||||
|
||||
const headers: Record<string, string> = {
|
||||
"Content-Type": "application/json",
|
||||
...(options.headers as Record<string, string>),
|
||||
@@ -128,7 +135,8 @@ async function apiFetch<T>(
|
||||
headers["Authorization"] = `Bearer ${token}`;
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}${endpoint}`, {
|
||||
const fullUrl = `${API_BASE_URL}${endpoint}`;
|
||||
const response = await fetch(fullUrl, {
|
||||
...options,
|
||||
headers,
|
||||
});
|
||||
|
Reference in New Issue
Block a user