From ceefb66ad8394b94f540f114187375303e471efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rog=C3=A9rio=20Moreira?= Date: Thu, 4 Apr 2024 15:01:33 +0100 Subject: [PATCH] CF fixes --- next.config.js | 3 +++ pages/api/bookmarks.ts | 2 +- pages/api/energy.ts | 49 ------------------------------------------ pages/api/og.tsx | 4 ---- 4 files changed, 4 insertions(+), 54 deletions(-) delete mode 100644 pages/api/energy.ts diff --git a/next.config.js b/next.config.js index 71d5e12f8..9079d27ef 100644 --- a/next.config.js +++ b/next.config.js @@ -33,6 +33,9 @@ const securityHeaders = [ module.exports = { swcMinify: true, reactStrictMode: true, + experimental: { + runtime: 'experimental-edge', + }, images: { remotePatterns: [ { diff --git a/pages/api/bookmarks.ts b/pages/api/bookmarks.ts index c287857fa..963e77ab1 100644 --- a/pages/api/bookmarks.ts +++ b/pages/api/bookmarks.ts @@ -6,7 +6,7 @@ import toJson from 'lib/to-json' export default async function handler(req: NextApiRequest, res: NextApiResponse) { if (req.method === 'GET') { try { - const allBookmarks = await prisma.bookmark.findMany({cacheStrategy: { ttl: 60 }}) + const allBookmarks = await prisma.bookmark.findMany({cacheStrategy: {ttl: 60}}) return res.status(200).json(toJson(allBookmarks)) } catch (e) { diff --git a/pages/api/energy.ts b/pages/api/energy.ts deleted file mode 100644 index 35e14b51b..000000000 --- a/pages/api/energy.ts +++ /dev/null @@ -1,49 +0,0 @@ -import type {NextApiRequest, NextApiResponse} from 'next' - -type Data = - | Array<{ - type: string - current: number - dailyHistory: Array<{valor: number; hora: string}> - }> - | {error: string} - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - let data = await fetch('https://datahub.ren.pt/service/Electricity/ProductionBreakdown/1266', { - method: 'POST', - headers: { - accept: '*/*', - 'accept-language': 'en', - 'sec-fetch-dest': 'empty', - 'sec-fetch-mode': 'cors', - 'sec-fetch-site': 'same-origin', - 'x-requested-with': 'XMLHttpRequest', - Referer: 'https://datahub.ren.pt/pt/', - 'Referrer-Policy': 'strict-origin-when-cross-origin', - }, - body: null, - }) - - let dataResponse = await data.json() - - if (data.status === 200) { - const series = dataResponse?.series - let energy = [] - - series.forEach(serie => { - const finalSerie = { - type: serie?.name, - current: serie?.data[serie?.data.length - 1], - dailyHistory: serie.data.map((medicao, index) => ({ - valor: medicao, - hora: dataResponse?.xAxis?.categories[index], - })), - } - energy.push(finalSerie) - }) - - res.status(200).json(energy) - } else { - res.status(500).json({error: 'Error fetching data'}) - } -} diff --git a/pages/api/og.tsx b/pages/api/og.tsx index a71fc6811..f6ba5bcdb 100644 --- a/pages/api/og.tsx +++ b/pages/api/og.tsx @@ -3,10 +3,6 @@ import {ImageResponse} from '@vercel/og' import {NextRequest} from 'next/server' -export const config = { - runtime: 'experimental-edge', -} - const fontRegular = fetch( new URL('../../public/fonts/IBMPlexSans-Regular.ttf', import.meta.url), ).then(res => res.arrayBuffer())