mirror of
https://github.com/traberph/short.git
synced 2026-11-22 22:55:12 +00:00
Containerization
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
Dockerfile
|
||||||
|
.dockerignore
|
||||||
|
node_modules
|
||||||
|
npm-debug.log
|
||||||
|
README.md
|
||||||
|
.next
|
||||||
|
.git
|
||||||
+74
@@ -0,0 +1,74 @@
|
|||||||
|
FROM node:18-alpine AS base
|
||||||
|
|
||||||
|
# Install dependencies only when needed
|
||||||
|
FROM base AS deps
|
||||||
|
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
||||||
|
RUN apk add --no-cache libc6-compat
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install dependencies based on the preferred package manager
|
||||||
|
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
|
||||||
|
RUN \
|
||||||
|
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
||||||
|
elif [ -f package-lock.json ]; then npm ci; \
|
||||||
|
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
|
||||||
|
else echo "Lockfile not found." && exit 1; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Rebuild the source code only when needed
|
||||||
|
FROM base AS builder
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
## WORKAROUND:
|
||||||
|
RUN rm -rf src/app/~/dash
|
||||||
|
RUN rm -rf src/app/actions
|
||||||
|
|
||||||
|
# Next.js collects completely anonymous telemetry data about general usage.
|
||||||
|
# Learn more here: https://nextjs.org/telemetry
|
||||||
|
# Uncomment the following line in case you want to disable telemetry during the build.
|
||||||
|
# ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
|
|
||||||
|
RUN npx prisma generate
|
||||||
|
|
||||||
|
RUN \
|
||||||
|
if [ -f yarn.lock ]; then yarn run build; \
|
||||||
|
elif [ -f package-lock.json ]; then npm run build; \
|
||||||
|
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
|
||||||
|
else echo "Lockfile not found." && exit 1; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Production image, copy all the files and run next
|
||||||
|
FROM base AS runner
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
# Uncomment the following line in case you want to disable telemetry during runtime.
|
||||||
|
# ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
|
|
||||||
|
RUN addgroup --system --gid 1001 nodejs
|
||||||
|
RUN adduser --system --uid 1001 nextjs
|
||||||
|
|
||||||
|
COPY --from=builder /app/public ./public
|
||||||
|
|
||||||
|
# Set the correct permission for prerender cache
|
||||||
|
RUN mkdir .next
|
||||||
|
RUN chown nextjs:nodejs .next
|
||||||
|
|
||||||
|
# Automatically leverage output traces to reduce image size
|
||||||
|
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
|
|
||||||
|
USER nextjs
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
ENV PORT=3000
|
||||||
|
|
||||||
|
# server.js is created by next build from the standalone output
|
||||||
|
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
|
||||||
|
ENV HOSTNAME="0.0.0.0"
|
||||||
|
CMD ["node", "server.js"]
|
||||||
+5
-1
@@ -9,4 +9,8 @@ services:
|
|||||||
- "5432:5432"
|
- "5432:5432"
|
||||||
volumes:
|
volumes:
|
||||||
- ./.vol_db:/var/lib/postgresql/data
|
- ./.vol_db:/var/lib/postgresql/data
|
||||||
|
|
||||||
|
web:
|
||||||
|
build: .
|
||||||
|
ports:
|
||||||
|
- 3000:3000
|
||||||
+2
-1
@@ -11,7 +11,8 @@ const nextConfig = {
|
|||||||
hostname: 'logo.clearbit.com',
|
hostname: 'logo.clearbit.com',
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
output: "standalone",
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -5,10 +5,10 @@ let prisma: PrismaClient;
|
|||||||
if (process.env.NODE_ENV === 'production') {
|
if (process.env.NODE_ENV === 'production') {
|
||||||
prisma = new PrismaClient();
|
prisma = new PrismaClient();
|
||||||
} else {
|
} else {
|
||||||
if (!global.prisma) {
|
if (!(global as any).prisma) {
|
||||||
global.prisma = new PrismaClient();
|
(global as any).prisma = new PrismaClient();
|
||||||
}
|
}
|
||||||
prisma = global.prisma;
|
prisma = (global as any).prisma;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default prisma;
|
export default prisma;
|
||||||
@@ -68,7 +68,7 @@ export async function createLinkBlock(prevState: any, formData: FormData) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
revalidatePath("/dash");
|
revalidatePath("/~/dash");
|
||||||
revalidatePath(`/~/dash/${data.data.customPageUuid}/page`);
|
revalidatePath(`/~/dash/${data.data.customPageUuid}/page`);
|
||||||
revalidatePath(`/${customPage.page.shortcode}`);
|
revalidatePath(`/${customPage.page.shortcode}`);
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ export async function deleteLinkBlock(prevState: any, formData: FormData) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
revalidatePath("/dash");
|
revalidatePath("/~/dash");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
message: "Link block deleted"
|
message: "Link block deleted"
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import prisma from "../../prisma/prisma";
|
import prisma from "../../prisma/prisma";
|
||||||
import { revalidatePath } from "next/cache";
|
import { revalidatePath } from "next/cache";
|
||||||
import { error } from "console";
|
|
||||||
|
|
||||||
export async function createCustomPage(prevState: any, fromData: FormData) {
|
export async function createCustomPage(prevState: any, fromData: FormData) {
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
@@ -49,12 +48,13 @@ export async function createCustomPage(prevState: any, fromData: FormData) {
|
|||||||
return {
|
return {
|
||||||
message: "Shortcode already exists",
|
message: "Shortcode already exists",
|
||||||
error: {
|
error: {
|
||||||
shortcode: "Shortcode already exists"
|
shortcode: ["Shortcode already exists"]
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
revalidatePath("/dash");
|
revalidatePath("/~/dash");
|
||||||
return {
|
return {
|
||||||
message: "Page created",
|
message: "Page created",
|
||||||
};
|
};
|
||||||
@@ -93,7 +93,7 @@ export async function createRedirectPage(prevState: any, fromData: FormData) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
revalidatePath("/dash");
|
revalidatePath("/~/dash");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
message: "URL created",
|
message: "URL created",
|
||||||
@@ -141,7 +141,7 @@ export async function deletePage(prevState: any, fromData: FormData) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
revalidatePath("/dash");
|
revalidatePath("/~/dash");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
message: "Page deleted",
|
message: "Page deleted",
|
||||||
@@ -178,7 +178,7 @@ export async function pinPageToRoot(prevState: any, fromData: FormData) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
revalidatePath("/dash");
|
revalidatePath("/~/dash");
|
||||||
revalidatePath("/");
|
revalidatePath("/");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ import { headers } from "next/headers";
|
|||||||
import { notFound, redirect, RedirectType } from "next/navigation";
|
import { notFound, redirect, RedirectType } from "next/navigation";
|
||||||
import { sha256 } from "js-sha256";
|
import { sha256 } from "js-sha256";
|
||||||
import CustomPageComponent from "@/components/CustomPageComponent";
|
import CustomPageComponent from "@/components/CustomPageComponent";
|
||||||
|
import { PageProps } from "../../../.next/types/app/layout";
|
||||||
|
|
||||||
export default async function RedirectToUrl({ params }: { params: { shortcode: string } }) {
|
export default async function RedirectToUrl({ params }: PageProps) {
|
||||||
|
|
||||||
const { shortcode } = await params;
|
const { shortcode } = await params;
|
||||||
|
|
||||||
@@ -21,7 +22,7 @@ export default async function RedirectToUrl({ params }: { params: { shortcode: s
|
|||||||
return notFound()
|
return notFound()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logg the visit
|
// Log the visit
|
||||||
const requestHeaders = await headers();
|
const requestHeaders = await headers();
|
||||||
const userAgent = requestHeaders.get('user-agent') || 'unknown';
|
const userAgent = requestHeaders.get('user-agent') || 'unknown';
|
||||||
const ip = requestHeaders.get('x-forwarded-for') || 'unknown';
|
const ip = requestHeaders.get('x-forwarded-for') || 'unknown';
|
||||||
|
|||||||
@@ -8,7 +8,13 @@ import LinkFavicon from "@/components/LinkFavicon";
|
|||||||
import { hashToColor } from "@/utils";
|
import { hashToColor } from "@/utils";
|
||||||
import PinPageToRootForm from "@/components/forms/pinPageToRootForm";
|
import PinPageToRootForm from "@/components/forms/pinPageToRootForm";
|
||||||
|
|
||||||
export default async function DetailedStats({ params }: { params: { uuid: string } }) {
|
interface PageProps {
|
||||||
|
params: Promise<{
|
||||||
|
uuid: string
|
||||||
|
}>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function DetailedStats({ params } : PageProps) {
|
||||||
|
|
||||||
const { uuid } = await params;
|
const { uuid } = await params;
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { createCustomPage } from "@/actions/page_actions";
|
|||||||
import { useActionState } from "react";
|
import { useActionState } from "react";
|
||||||
import SubmitButton from "../SubmitButton";
|
import SubmitButton from "../SubmitButton";
|
||||||
|
|
||||||
|
|
||||||
export default function CreateCustomPageForm() {
|
export default function CreateCustomPageForm() {
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
|
|||||||
Reference in New Issue
Block a user