Skip to content

Commit

Permalink
revert: #1714 migrate to axios.get
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-rw committed Jan 14, 2024
1 parent c799226 commit c09b4c5
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/server/api/routers/app.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { TRPCError } from '@trpc/server';
import { AxiosError } from 'axios';
import axios, { AxiosError } from 'axios';
import Consola from 'consola';
import { z } from 'zod';
import { isStatusOk } from '~/components/Dashboard/Tiles/Apps/AppPing';
import { getConfig } from '~/tools/config/getConfig';
import { AppType } from '~/types/app';

import { createTRPCRouter, publicProcedure } from '../trpc';
import * as https from 'https';

export const appRouter = createTRPCRouter({
ping: publicProcedure
Expand All @@ -29,14 +30,21 @@ export const appRouter = createTRPCRouter({
});
}

const res = await fetch(app.url, {
const agent = new https.Agent({
rejectUnauthorized: false,

Check failure

Code scanning / CodeQL

Disabling certificate validation High

Disabling certificate validation is strongly discouraged.
requestCert: false
});

return await axios.get(app.url, {
method: 'GET',
cache: 'force-cache',
headers: {
// Cache for 5 minutes
'Cache-Control': 'max-age=300',
'Content-Type': 'application/json',
'Cache-Control': 'max-age=300'
},
httpAgent: agent,
httpsAgent: agent,
timeout: 12 * 1000, // 12 seconds,
maxRedirects: 3
})
.then((response) => ({
status: response.status,
Expand Down Expand Up @@ -70,6 +78,5 @@ export const appRouter = createTRPCRouter({
message: `Unexpected response: ${error.message}`,
});
});
return res;
}),
});

0 comments on commit c09b4c5

Please sign in to comment.