Made configurable with .env
This commit is contained in:
parent
fd0440e9ae
commit
11d5d43dce
6 changed files with 12 additions and 10 deletions
|
|
@ -4,7 +4,7 @@ import { NextResponse } from "next/server";
|
||||||
|
|
||||||
export async function GET(request: Request, { params }: { params: { route: number } }) {
|
export async function GET(request: Request, { params }: { params: { route: number } }) {
|
||||||
const slug = params.route;
|
const slug = params.route;
|
||||||
const res = await fetch(`http://192.168.1.69:2019/config/apps/http/servers/srv0/routes/${slug}`, { cache: 'no-store' });
|
const res = await fetch(`${process.env.CADDY_API}/config/apps/http/servers/srv0/routes/${slug}`, { cache: 'no-store' });
|
||||||
let route: Route = await res.json();
|
let route: Route = await res.json();
|
||||||
|
|
||||||
if (!res.ok) return onError('Failed to get route');
|
if (!res.ok) return onError('Failed to get route');
|
||||||
|
|
@ -44,7 +44,7 @@ export async function PUT(request: Request, { params }: { params: { route: numbe
|
||||||
const slug = params.route;
|
const slug = params.route;
|
||||||
let route: Route = await request.json();
|
let route: Route = await request.json();
|
||||||
|
|
||||||
const res = await fetch(`http://192.168.1.69:2019/config/apps/http/servers/srv0/routes/${slug}`, {
|
const res = await fetch(`${process.env.CADDY_API}/config/apps/http/servers/srv0/routes/${slug}`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ export async function DELETE(req: Request) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const res = await fetch(`http://192.168.1.69:2019/config/apps/http/servers/srv0/routes/${index}`, {
|
const res = await fetch(`${process.env.CADDY_API}/config/apps/http/servers/srv0/routes/${index}`, {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
export async function GET(request: Request) {
|
export async function GET(request: Request) {
|
||||||
const res = await fetch(`http://192.168.1.69:2019/config/apps/http/servers/`, { cache: 'no-store' });
|
const res = await fetch(`${process.env.CADDY_API}/config/apps/http/servers/`, { cache: 'no-store' });
|
||||||
|
|
||||||
if (!res.ok)
|
if (!res.ok)
|
||||||
throw new Error('Failed to fetch caddy config. Please check the network and try again.');
|
throw new Error('Failed to fetch caddy config. Please check the network and try again.');
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ export async function useConfig() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function useUpstreamRoutes(route: Route) {
|
export async function useUpstreamRoutes(route: Route) {
|
||||||
const { data, error, isLoading } = useSWR('http://192.168.1.69:2019/reverse_proxy/upstreams', fetcher);
|
const { data, error, isLoading } = useSWR(`${process.env.CADDY_API}/reverse_proxy/upstreams`, fetcher);
|
||||||
return {
|
return {
|
||||||
data,
|
data,
|
||||||
error,
|
error,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
'use server';
|
'use server';
|
||||||
|
|
||||||
export async function getConfig() {
|
export async function getConfig() {
|
||||||
const res = await fetch('http://192.168.1.69:2019/config/', {
|
const res = await fetch(`${process.env.CADDY_API}/config/`, {
|
||||||
cache: 'no-cache',
|
cache: 'no-cache',
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
throw new Error('Failed to fetch caddy config. Please check the network and try again.');
|
throw new Error('Failed to fetch caddy config. Please check the network and try again.');
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getServer() {
|
export async function getServer() {
|
||||||
const res = await fetch('http://localhost:3000/api/caddy/servers').catch(() => {
|
const res = await fetch(`${process.env.URL}/api/caddy/servers`).catch(() => {
|
||||||
throw new Error('Failed to fetch caddy servers. Please check the network and try again.');
|
throw new Error('Failed to fetch caddy servers. Please check the network and try again.');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -33,7 +33,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getUpstreamRequests(route: Route) {
|
export async function getUpstreamRequests(route: Route) {
|
||||||
let upstreams: UpstreamRequest[] = await fetch(`http://192.168.1.69:2019/reverse_proxy/upstreams`, {
|
let upstreams: UpstreamRequest[] = await fetch(`${process.env.CADDY_API}/reverse_proxy/upstreams`, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
|
|
@ -45,7 +45,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getRoutes() {
|
export async function getRoutes() {
|
||||||
let res = await fetch('http://localhost:3000/api/caddy/routes', { cache: 'no-cache' }).catch(() => {
|
let res = await fetch(`${process.env.URL}/api/caddy/routes`, { cache: 'no-cache' }).catch(() => {
|
||||||
throw new Error('Failed to fetch routes. Please check the network and try again.');
|
throw new Error('Failed to fetch routes. Please check the network and try again.');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = {}
|
const nextConfig = {
|
||||||
|
output: "standalone"
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = nextConfig
|
module.exports = nextConfig
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue