fix API URL prefix

This commit is contained in:
2022-03-31 15:45:23 +08:00
parent 25ad82b066
commit 44c3c620b0
2 changed files with 11 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
// basePath: '/itsc',
}
module.exports = nextConfig

View File

@@ -16,6 +16,9 @@ import {
} from "@mui/material";
import { useEffect, useState } from "react";
import { useRouter } from "next/router";
import config from '../next.config';
const prefix = config.basePath ? config.basePath : '';
export default function Time(props) {
const [ranges, setRanges] = useState([]);
@@ -30,7 +33,7 @@ export default function Time(props) {
const router = useRouter();
const setStarted = (started) => {
fetch("/api/time/started", {
fetch(`${prefix}/api/time/started`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
@@ -57,7 +60,7 @@ export default function Time(props) {
};
const getLimit = () => {
fetch("/api/time/limit", {
fetch(`${prefix}/api/time/limit`, {
method: "GET",
headers: {
"Content-Type": "application/json",
@@ -70,7 +73,7 @@ export default function Time(props) {
};
const addRange = () => {
fetch("/api/time/ranges", {
fetch(`${prefix}/api/time/ranges`, {
method: "POST",
headers: {
"Content-Type": "application/json",
@@ -95,7 +98,7 @@ export default function Time(props) {
const refreshRanges = () => {
getLimit();
fetch("/api/time/ranges")
fetch(`${prefix}/api/time/ranges`)
.then((res) => res.json())
.then((res) => {
if (res.error) {
@@ -108,7 +111,7 @@ export default function Time(props) {
};
const deleteRange = (id) => {
fetch(`/api/time/ranges/${id}`, {
fetch(`${prefix}/api/time/ranges/${id}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
@@ -128,7 +131,7 @@ export default function Time(props) {
};
const updateUsername = (id, username) => {
fetch(`/api/time/ranges/${id}`, {
fetch(`${prefix}/api/time/ranges/${id}`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
@@ -149,7 +152,7 @@ export default function Time(props) {
};
const updateLimit = (limit) => {
fetch("/api/time/limit", {
fetch(`${prefix}/api/time/limit`, {
method: "PUT",
headers: {
"Content-Type": "application/json",