mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-10 23:45:48 +01:00
⚡ Make proxied requests for calendar
This commit is contained in:
@@ -37,11 +37,7 @@ export default function CalendarComponent(props: any) {
|
|||||||
if (!service || !service.apiKey) {
|
if (!service || !service.apiKey) {
|
||||||
return Promise.resolve({ data: [] });
|
return Promise.resolve({ data: [] });
|
||||||
}
|
}
|
||||||
return axios.get(`/api/modules/calendar?type=${type}`, {
|
return axios.post(`/api/modules/calendar?type=${type}`, { ...service });
|
||||||
data: {
|
|
||||||
body: service,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import axios from 'axios';
|
|||||||
import { NextApiRequest, NextApiResponse } from 'next';
|
import { NextApiRequest, NextApiResponse } from 'next';
|
||||||
import { serviceItem } from '../../../tools/types';
|
import { serviceItem } from '../../../tools/types';
|
||||||
|
|
||||||
async function Get(req: NextApiRequest, res: NextApiResponse) {
|
async function Post(req: NextApiRequest, res: NextApiResponse) {
|
||||||
// Parse req.body as a ServiceItem
|
// Parse req.body as a ServiceItem
|
||||||
const nextMonth = new Date(new Date().setMonth(new Date().getMonth() + 2)).toISOString();
|
const nextMonth = new Date(new Date().setMonth(new Date().getMonth() + 2)).toISOString();
|
||||||
const lastMonth = new Date(new Date().setMonth(new Date().getMonth() - 2)).toISOString();
|
const lastMonth = new Date(new Date().setMonth(new Date().getMonth() - 2)).toISOString();
|
||||||
@@ -45,6 +45,7 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
}
|
}
|
||||||
// Get the origin URL
|
// Get the origin URL
|
||||||
const { origin } = new URL(service.url);
|
const { origin } = new URL(service.url);
|
||||||
|
const pined = `${origin}${url?.url}?apiKey=${service.apiKey}&end=${nextMonth}&start=${lastMonth}`;
|
||||||
const data = await axios.get(
|
const data = await axios.get(
|
||||||
`${origin}${url?.url}?apiKey=${service.apiKey}&end=${nextMonth}&start=${lastMonth}`
|
`${origin}${url?.url}?apiKey=${service.apiKey}&end=${nextMonth}&start=${lastMonth}`
|
||||||
);
|
);
|
||||||
@@ -56,8 +57,8 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
|
|
||||||
export default async (req: NextApiRequest, res: NextApiResponse) => {
|
export default async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
// Filter out if the reuqest is a POST or a GET
|
// Filter out if the reuqest is a POST or a GET
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'POST') {
|
||||||
return Get(req, res);
|
return Post(req, res);
|
||||||
}
|
}
|
||||||
return res.status(405).json({
|
return res.status(405).json({
|
||||||
statusCode: 405,
|
statusCode: 405,
|
||||||
|
|||||||
Reference in New Issue
Block a user