remove the BasePath

This commit is contained in:
Erza Bytyci
2026-05-08 10:03:18 +00:00
parent 2ae38c974a
commit 550033b9cf
28 changed files with 61 additions and 140 deletions
-1
View File
@@ -39,7 +39,6 @@ ENV SESSION_SECRET=$SESSION_SECRET \
DB_PASSWORD=$DB_PASSWORD \
DB_NAME=$DB_NAME \
NODE_ENV=$NODE_ENV \
NEXT_PUBLIC_BASE_PATH=$NEXT_PUBLIC_BASE_PATH
# Install ALL dependencies (including dev) for build
RUN npm ci
+1 -6
View File
@@ -1,12 +1,8 @@
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
/** @type {import('next').NextConfig} */
const nextConfig =
{
output: 'standalone',
basePath,
eslint: {
ignoreDuringBuilds: true,
},
@@ -18,8 +14,7 @@ const nextConfig =
DB_PORT: process.env.DB_PORT || '5432',
DB_USER: process.env.DB_USER || 'postgres',
DB_PASSWORD: process.env.DB_PASSWORD || 'password',
DB_NAME: process.env.DB_NAME || 'postgres',
NEXT_PUBLIC_BASE_PATH: basePath
DB_NAME: process.env.DB_NAME || 'postgres'
}
};
@@ -8,7 +8,6 @@ import { Button } from "@/components/ui/button";
import useQuery from "@/shared/hooks/useQuery";
import "./click.css";
import WordSelectionExercise from "@/components/ui/click/click.js";
import { withBasePath } from "@/shared/utils/basePath";
export default function CreateExercise() {
const router = useRouter();
@@ -67,19 +66,16 @@ export default function CreateExercise() {
const handleSaveExercise = async () => {
try {
if (isEditMode) {
const response = await fetch(
withBasePath(`/api/admin/exercises/click/${click_id}`),
{
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
title,
targetCategory,
targetWords: selectedWords,
allWords,
}),
}
);
const response = await fetch(`/api/admin/exercises/click/${click_id}`, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
title,
targetCategory,
targetWords: selectedWords,
allWords,
}),
});
const data = await response.json();
if (!response.ok) {
@@ -5,7 +5,6 @@ import { useParams, useRouter } from "next/navigation";
import { Button } from "@/components/ui/button";
import { Row } from "@/components/ui/layout/container";
import useQuery from "@/shared/hooks/useQuery";
import { withBasePath } from "@/shared/utils/basePath";
import "./admin.css";
const EMPTY_PAIR = () => ({ leftItem: "", rightItem: "" });
@@ -91,26 +90,20 @@ export default function DndMatchAdminPage() {
setIsSubmitting(true);
if (isEditMode) {
const res = await fetch(
withBasePath(`/api/admin/exercises/dnd-match/${match_id}`),
{
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
}
);
const res = await fetch(`/api/admin/exercises/dnd-match/${match_id}`, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error || "Fehler beim Speichern.");
router.push("/grammar/exercises/dnd-match");
} else {
const res = await fetch(
withBasePath("/api/admin/exercises/dnd-match"),
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
}
);
const res = await fetch(`/api/admin/exercises/dnd-match`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error || "Fehler beim Erstellen.");
router.push(`/grammar/exercises/dnd-match/${data.id}`);
@@ -9,7 +9,6 @@ import { useRequest } from "@/shared/hooks/useRequest";
import { useParams, useRouter } from "next/navigation";
import useQuery from "@/shared/hooks/useQuery";
import PreviewDragDrop from "@/components/ui/dragdrop/dragdrop_preview";
import { withBasePath } from "@/shared/utils/basePath";
export default function DragdropAdminPage() {
const { dnd_id } = useParams();
@@ -86,7 +85,7 @@ export default function DragdropAdminPage() {
if (isEditMode) {
const response = await fetch(
withBasePath(`/api/admin/exercises/dragdrop/${dnd_id}`),
`/api/admin/exercises/dragdrop/${dnd_id}`,
{
method: "PUT",
headers: { "Content-Type": "application/json" },
@@ -6,7 +6,6 @@ import { useEffect, useState } from "react";
import { useRouter, useParams } from "next/navigation";
import useQuery from "@/shared/hooks/useQuery";
import "../../../multichoice/multichoice.css";
import { withBasePath } from "@/shared/utils/basePath";
export default function EditFreeFormExercisePage() {
const router = useRouter();
@@ -131,7 +130,7 @@ export default function EditFreeFormExercisePage() {
}
const response = await fetch(
withBasePath(`/api/admin/exercises/free-form/${exercise_id}`),
`/api/admin/exercises/free-form/${exercise_id}`,
{
method: "PUT",
headers: {
@@ -4,7 +4,6 @@ import { useParams, useRouter } from "next/navigation";
import { Button } from "@/components/ui/button";
import useQuery from "@/shared/hooks/useQuery";
import "./multichoice.css";
import { withBasePath } from "@/shared/utils/basePath";
export default function CreateMultichoicePage() {
const router = useRouter();
@@ -174,8 +173,8 @@ export default function CreateMultichoicePage() {
});
const endpoint = isEditMode
? withBasePath(`/api/admin/exercises/multichoice/${exercise_id}`)
: withBasePath("/api/admin/exercises/multichoice");
? `/api/admin/exercises/multichoice/${exercise_id}`
: `/api/admin/exercises/multichoice`;
const res = await fetch(endpoint, {
method: isEditMode ? "PUT" : "POST",
@@ -6,7 +6,6 @@ import { Button } from "@/components/ui/button";
import Editor from "@/components/ui/editor";
import layout from "@/shared/styles/layout.module.css";
import { useRouter, useSearchParams } from "next/navigation";
import { withBasePath } from "@/shared/utils/basePath";
export default function EditorSection({
initialContent,
@@ -50,19 +49,16 @@ export default function EditorSection({
const jsonData = JSON.stringify(requestBody);
if (!pageExists && type === "grammar") {
const createRes = await fetch(
withBasePath(`/api/admin/pages/${type}/${slug}`),
{
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
method: "POST",
body: JSON.stringify({
title: titleInput,
}),
}
);
const createRes = await fetch(`/api/admin/pages/${type}/${slug}`, {
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
method: "POST",
body: JSON.stringify({
title: titleInput,
}),
});
if (!createRes.ok && createRes.status !== 200) {
setEditorMessage({
@@ -72,7 +68,7 @@ export default function EditorSection({
return;
}
}
const res = await fetch(withBasePath(`/api/admin/pages/${type}/${slug}`), {
const res = await fetch(`/api/admin/pages/${type}/${slug}`, {
headers: {
Accept: "application/json",
"Content-Type": "application/json",
@@ -6,7 +6,6 @@ import { useRequest } from "@/shared/hooks/useRequest";
import { useRouter, useSearchParams } from "next/navigation";
import { zodErrorToFormErrors } from "@/shared/schemas/schema-utils";
import Editor from "@/components/ui/editor";
import { withBasePath } from "@/shared/utils/basePath";
const defaultFormErrors = {
word: "",
@@ -32,9 +31,7 @@ export default function CreateGlossaryEntry() {
const loadEntry = async () => {
try {
setIsLoadingEntry(true);
const response = await fetch(
withBasePath(`/api/admin/glossary?id=${entryId}`)
);
const response = await fetch(`/api/admin/glossary?id=${entryId}`);
if (!response.ok) {
throw new Error("Failed to load glossary entry");
}
+2 -3
View File
@@ -5,7 +5,6 @@ import { Button } from "@/components/ui/button";
import layout from "@/shared/styles/layout.module.css";
import styles from "./new-page.module.css";
import { useRouter } from "next/navigation";
import { withBasePath } from "@/shared/utils/basePath";
export default function NewPage() {
const [type, setType] = useState("resources");
@@ -18,7 +17,7 @@ export default function NewPage() {
useEffect(() => {
if (type !== "grammar") return;
fetch(withBasePath("/api/admin/grammar-topics"))
fetch("/api/admin/grammar-topics")
.then((res) => res.json())
.then((data) => {
setGrammarTopics(data);
@@ -50,7 +49,7 @@ export default function NewPage() {
}
}
const response = await fetch(withBasePath(`/api/admin/pages`), {
const response = await fetch(`/api/admin/pages`, {
method: "POST",
headers: {
"Content-Type": "application/json",
+2 -3
View File
@@ -4,7 +4,6 @@ import { useEffect, useState } from "react";
import { useRouter } from "next/navigation";
import { Container } from "@/components/ui/layout/container";
import { Button } from "@/components/ui/button";
import { withBasePath } from "@/shared/utils/basePath";
export default function EditEmail() {
const [user, setUser] = useState("");
@@ -17,7 +16,7 @@ export default function EditEmail() {
useEffect(() => {
const fetchCurrentUser = async () => {
try {
const res = await fetch(withBasePath("/api/edit_email"), {
const res = await fetch("/api/edit_email", {
method: "GET",
});
if (res.ok) {
@@ -44,7 +43,7 @@ export default function EditEmail() {
return;
}
const res = await fetch(withBasePath("/api/edit_email"), {
const res = await fetch("/api/edit_email", {
method: "POST",
headers: {
"Content-Type": "application/json",
@@ -4,7 +4,6 @@ import { useState } from "react";
import { useRouter } from "next/navigation";
import { Container } from "@/components/ui/layout/container";
import { Button } from "@/components/ui/button";
import { withBasePath } from "@/shared/utils/basePath";
export default function EditPassword() {
const [currentPassword, setCurrentPassword] = useState("");
@@ -25,7 +24,7 @@ export default function EditPassword() {
return;
}
const res = await fetch(withBasePath("/api/edit_password"), {
const res = await fetch("/api/edit_password", {
method: "POST",
headers: {
"Content-Type": "application/json",
+1 -2
View File
@@ -6,7 +6,6 @@ import styles from "../page.module.css";
import { Container } from "@/components/ui/layout/container";
import { LinkButton } from "@/components/ui/linkbutton";
import { Grid } from "@radix-ui/themes";
import { withBasePath } from "@/shared/utils/basePath";
export default function EditInfo() {
const [user, setUser] = useState(null);
@@ -14,7 +13,7 @@ export default function EditInfo() {
useEffect(() => {
const getUser = async () => {
const res = await fetch(withBasePath("/api/edit_info"));
const res = await fetch("/api/edit_info");
if (res.status === 401) {
router.replace("/auth/login");
@@ -5,7 +5,6 @@ import { Container, Row, Column } from "@/components/ui/layout/container";
import useQuery from "@/shared/hooks/useQuery";
import { ExerciseLinkButton } from "@/components/ui/button/exercise-link-button";
import { Button } from "@/components/ui/button";
import { withBasePath } from "@/shared/utils/basePath";
export default function ClickExercisesPage() {
const {
@@ -21,12 +20,9 @@ export default function ClickExercisesPage() {
if (!confirmed) return;
try {
const response = await fetch(
withBasePath(`/api/admin/exercises/click/${exerciseId}`),
{
method: "DELETE",
}
);
const response = await fetch(`/api/admin/exercises/click/${exerciseId}`, {
method: "DELETE",
});
if (!response.ok) {
throw new Error("Fehler beim Löschen der Übung.");
@@ -5,7 +5,6 @@ import { Container, Row, Column } from "@/components/ui/layout/container";
import useQuery from "@/shared/hooks/useQuery";
import { ExerciseLinkButton } from "@/components/ui/button/exercise-link-button";
import { Button } from "@/components/ui/button";
import { withBasePath } from "@/shared/utils/basePath";
export default function DndMatchExercisesPage() {
const {
@@ -21,7 +20,7 @@ export default function DndMatchExercisesPage() {
try {
const response = await fetch(
withBasePath(`/api/admin/exercises/dnd-match/${exerciseId}`),
`/api/admin/exercises/dnd-match/${exerciseId}`,
{
method: "DELETE",
}
@@ -5,7 +5,6 @@ import { Container, Row, Column } from "@/components/ui/layout/container";
import useQuery from "@/shared/hooks/useQuery";
import { ExerciseLinkButton } from "@/components/ui/button/exercise-link-button";
import { Button } from "@/components/ui/button";
import { withBasePath } from "@/shared/utils/basePath";
export default function DragdropExercisesPage() {
const {
@@ -22,7 +21,7 @@ export default function DragdropExercisesPage() {
try {
const response = await fetch(
withBasePath(`/api/admin/exercises/dragdrop/${exerciseId}`),
`/api/admin/exercises/dragdrop/${exerciseId}`,
{
method: "DELETE",
}
@@ -5,7 +5,6 @@ import { Container, Row, Column } from "@/components/ui/layout/container";
import useQuery from "@/shared/hooks/useQuery";
import { ExerciseLinkButton } from "@/components/ui/button/exercise-link-button";
import { Button } from "@/components/ui/button";
import { withBasePath } from "@/shared/utils/basePath";
export default function FillInTheGapExercisesPage() {
const {
@@ -22,7 +21,7 @@ export default function FillInTheGapExercisesPage() {
try {
const response = await fetch(
withBasePath(`/api/admin/exercises/fillinthegap/${exerciseId}`),
`/api/admin/exercises/fillinthegap/${exerciseId}`,
{
method: "DELETE",
}
@@ -5,7 +5,6 @@ import { Container, Row, Column } from "@/components/ui/layout/container";
import useQuery from "@/shared/hooks/useQuery";
import { ExerciseLinkButton } from "@/components/ui/button/exercise-link-button";
import { Button } from "@/components/ui/button";
import { withBasePath } from "@/shared/utils/basePath";
export default function FreeFormExercisesPage() {
const {
@@ -22,7 +21,7 @@ export default function FreeFormExercisesPage() {
try {
const response = await fetch(
withBasePath(`/api/admin/exercises/free-form/${exerciseId}`),
`/api/admin/exercises/free-form/${exerciseId}`,
{
method: "DELETE",
}
@@ -5,7 +5,6 @@ import { Container, Column, Row } from "@/components/ui/layout/container";
import useQuery from "@/shared/hooks/useQuery";
import { ExerciseLinkButton } from "@/components/ui/button/exercise-link-button";
import { Button } from "@/components/ui/button";
import { withBasePath } from "@/shared/utils/basePath";
export default function MultichoiceExercisesPage() {
const {
@@ -22,7 +21,7 @@ export default function MultichoiceExercisesPage() {
try {
const response = await fetch(
withBasePath(`/api/admin/exercises/multichoice/${exerciseId}`),
`/api/admin/exercises/multichoice/${exerciseId}`,
{
method: "DELETE",
}
@@ -6,7 +6,6 @@ import { useRouter } from "next/navigation";
import { useUser } from "@/context/user.context";
import { Row } from "@/components/ui/layout/container";
import { useSearchParams } from "next/navigation";
import { withBasePath } from "@/shared/utils/basePath";
export default function AdminButtons({ type, slug, pageExists = true }) {
const { setActAs } = useUser();
@@ -18,7 +17,7 @@ export default function AdminButtons({ type, slug, pageExists = true }) {
const handleReset = async () => {
if (!confirm("Möchten Sie den Inhalt dieser Seite wirklich leeren?"))
return;
const res = await fetch(withBasePath(`/api/admin/pages/${type}/${slug}`), {
const res = await fetch(`/api/admin/pages/${type}/${slug}`, {
method: "PATCH",
});
@@ -64,7 +63,7 @@ export default function AdminButtons({ type, slug, pageExists = true }) {
} else if (type === "resources") {
redirectPath = "/learning"; // fallback
try {
const listRes = await fetch(withBasePath(`/api/pages/${type}`));
const listRes = await fetch(`/api/pages/${type}`);
if (listRes.ok) {
const data = await listRes.json();
const pages = Array.isArray(data?.pages) ? data.pages : [];
@@ -83,7 +82,7 @@ export default function AdminButtons({ type, slug, pageExists = true }) {
redirectPath = getFallbackPath(type);
}
const res = await fetch(withBasePath(`/api/admin/pages/${type}/${slug}`), {
const res = await fetch(`/api/admin/pages/${type}/${slug}`, {
method: "DELETE",
});
+1 -2
View File
@@ -3,7 +3,6 @@
import "./talkback.css";
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { withBasePath } from "@/shared/utils/basePath";
export default function TalkbackPage() {
const defaultSubject = "Rückmeldung von GRADESA 2.0";
@@ -45,7 +44,7 @@ export default function TalkbackPage() {
try {
setIsSending(true);
const response = await fetch(withBasePath("/api/talkback"), {
const response = await fetch("/api/talkback", {
method: "POST",
headers: {
"Content-Type": "application/json",
@@ -1,6 +1,5 @@
"use client";
import { Button } from "@/components/ui/button";
import { withBasePath } from "@/shared/utils/basePath";
export function ExerciseLinkButton({ href, children, ...props }) {
const copyToClipboard = async (e) => {
@@ -8,7 +7,7 @@ export function ExerciseLinkButton({ href, children, ...props }) {
e.stopPropagation();
try {
const origin = window.location.origin;
const url = `${origin}${withBasePath(href)}`;
const url = `${origin}${href}`;
await navigator.clipboard.writeText(url);
alert("Link kopiert!");
return true;
@@ -7,7 +7,6 @@ import { MatchCard } from "./MatchCard";
import { MatchSlot } from "./MatchSlot";
import { Button } from "@/components/ui/button";
import "./dnd-match.css";
import { withBasePath } from "@/shared/utils/basePath";
function shuffle(arr) {
const a = [...arr];
@@ -110,7 +109,7 @@ const MatchAreaInner = ({ exercise, exerciseId }) => {
}));
const res = await fetch(
withBasePath(`/api/exercises/dnd-match/${exerciseId}/answers`),
`/api/exercises/dnd-match/${exerciseId}/answers`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
+1 -4
View File
@@ -2,7 +2,6 @@ import { memo, useCallback, useState, useEffect } from "react";
import { WordBox } from "./wordbox.js";
import { Dustbin } from "./dustbin.js";
import { Button } from "@/components/ui/button";
import { withBasePath } from "@/shared/utils/basePath";
const Area = ({ exerciseID }) => {
const [dustbins, setDustbins] = useState([]);
@@ -23,9 +22,7 @@ const Area = ({ exerciseID }) => {
if (!exerciseID) return;
try {
const response = await fetch(
withBasePath(`/api/exercises/dragdrop/${exerciseID}`)
);
const response = await fetch(`/api/exercises/dragdrop/${exerciseID}`);
if (!response.ok) throw new Error("Fehler beim Laden der Übung.");
const data = await response.json();
@@ -5,7 +5,6 @@ import {
GlossaryParagraph,
GlossaryListItem,
} from "@/components/ui/glossary/GlossaryText";
import { BASE_PATH, withBasePath } from "@/shared/utils/basePath";
/**
* Normalize HTML attributes for use in React elements.
@@ -35,15 +34,6 @@ const normalizeAttribs = (attributes = {}) => {
return normalized;
};
const prefixRootRelativePath = (value) => {
if (typeof value !== "string") return value;
if (!value.startsWith("/") || value.startsWith("//")) return value;
if (BASE_PATH && (value === BASE_PATH || value.startsWith(`${BASE_PATH}/`))) {
return value;
}
return withBasePath(value);
};
/**
* RenderHTML
*
@@ -94,25 +84,11 @@ export default function RenderHTML({ data, disableGlossary = false }) {
// Legacy DB content can contain <Container> tags from old React markup.
// Render only children to preserve previous look without invalid tag warnings.
container: (_attributes, children) => <Fragment>{children}</Fragment>,
a: (attributes, children) => {
const safeAttribs = { ...attributes };
if (safeAttribs.href) {
safeAttribs.href = prefixRootRelativePath(safeAttribs.href);
}
return <a {...safeAttribs}>{children}</a>;
},
img: (attributes) => {
const safeAttribs = { ...attributes };
if (safeAttribs.src) {
safeAttribs.src = prefixRootRelativePath(safeAttribs.src);
}
return <img {...safeAttribs} />;
},
anchor: (attributes, children) => {
const safeAttribs = { ...attributes };
const href = safeAttribs.href || safeAttribs["data-href"];
if (href) {
safeAttribs["data-href"] = prefixRootRelativePath(href);
safeAttribs["data-href"] = href;
delete safeAttribs.href;
}
safeAttribs.className = [safeAttribs.className, "glossary-anchor"]
+1 -2
View File
@@ -14,7 +14,6 @@ import {
import { Button } from "../button";
import { useEffect, useState } from "react";
import { useIsMounted } from "@/shared/hooks/useIsMounted";
import { withBasePath } from "@/shared/utils/basePath";
const Sidebar = () => {
const { auth, setActAs, actAs } = useUser();
@@ -80,7 +79,7 @@ function StudentSideBar() {
const pathname = usePathname();
useEffect(() => {
fetch(withBasePath("/api/pages/resources"))
fetch("/api/pages/resources")
.then((res) => res.json())
.then((data) => {
setChapters(
+1 -2
View File
@@ -4,10 +4,9 @@ import { useState, useEffect, useRef, useMemo, memo } from "react";
import { useIsMounted } from "./useIsMounted";
import { useUser } from "@/context/user.context";
import { useSessionId } from "./useSessionId";
import { withBasePath } from "@/shared/utils/basePath";
export const axiosInstance = axios.create({
baseURL: withBasePath("/api"),
baseURL: "/api",
});
/**
-6
View File
@@ -1,6 +0,0 @@
export const BASE_PATH = process.env.NEXT_PUBLIC_BASE_PATH || "";
export function withBasePath(path) {
if (!path.startsWith("/")) return path;
return `${BASE_PATH}${path}`;
}