Fixed Next.js Middleware, Added API Route Caching, and Removed Unused Packages

This commit is contained in:
Ahmad 2024-12-23 14:14:15 -05:00
parent a25d2bf951
commit a9bd470c68
No known key found for this signature in database
GPG key ID: 8FD8A93530D182BF
5 changed files with 48 additions and 244 deletions

View file

@ -29,7 +29,14 @@ export async function GET(
take: 3,
});
return NextResponse.json(auditLogs);
return new NextResponse(JSON.stringify(auditLogs), {
status: 200,
headers: {
'Cache-Control': 'public, s-maxage=5',
'CDN-Cache-Control': 'public, s-maxage=60',
'Vercel-CDN-Cache-Control': 'public, s-maxage=3600',
},
});
} catch (error) {
return new NextResponse(JSON.stringify(error), { status: 500 });
}

View file

@ -34,7 +34,14 @@ export async function GET(
},
});
return NextResponse.json(card);
return new NextResponse(JSON.stringify(card), {
status: 200,
headers: {
'Cache-Control': 'public, s-maxage=1',
'CDN-Cache-Control': 'public, s-maxage=60',
'Vercel-CDN-Cache-Control': 'public, s-maxage=3600',
},
});
} catch (error) {
return new NextResponse(JSON.stringify(error), { status: 500 });
}

View file

@ -1,6 +1,5 @@
import { withSentryConfig } from '@sentry/nextjs';
import type { NextConfig } from 'next';
import compression from 'compression';
import { withContentCollections } from '@content-collections/next';
import createMDX from '@next/mdx';
@ -38,54 +37,49 @@ const nextConfig: NextConfig = {
},
pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
compress: true,
serverMiddleware: [compression()],
poweredByHeader: false,
};
const withMDX = createMDX({});
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
});
export default withContentCollections(
withBundleAnalyzer(
withSentryConfig(withMDX(nextConfig), {
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options
withSentryConfig(withMDX(nextConfig), {
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options
org: 'ahmadk953',
project: 'tasko',
org: 'ahmadk953',
project: 'tasko',
// Only print logs for uploading source maps in CI
silent: !process.env.CI,
// Only print logs for uploading source maps in CI
silent: !process.env.CI,
// For all available options, see:
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
// For all available options, see:
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: true,
// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: true,
// Automatically annotate React components to show their full name in breadcrumbs and session replay
reactComponentAnnotation: {
enabled: true,
},
// Automatically annotate React components to show their full name in breadcrumbs and session replay
reactComponentAnnotation: {
enabled: true,
},
// Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
// This can increase your server load as well as your hosting bill.
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
// side errors will fail.
tunnelRoute: '/monitoring',
// Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
// This can increase your server load as well as your hosting bill.
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
// side errors will fail.
tunnelRoute: '/monitoring',
// Hides source maps from generated client bundles
hideSourceMaps: true,
// Hides source maps from generated client bundles
hideSourceMaps: true,
// Automatically tree-shake Sentry logger statements to reduce bundle size
disableLogger: true,
// Automatically tree-shake Sentry logger statements to reduce bundle size
disableLogger: true,
// Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)
// See the following for more information:
// https://docs.sentry.io/product/crons/
// https://vercel.com/docs/cron-jobs
automaticVercelMonitors: true,
})
)
// Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)
// See the following for more information:
// https://docs.sentry.io/product/crons/
// https://vercel.com/docs/cron-jobs
automaticVercelMonitors: true,
})
);

View file

@ -16,7 +16,6 @@
"@hello-pangea/dnd": "^17.0.0",
"@mdx-js/loader": "^3.1.0",
"@mdx-js/react": "^3.1.0",
"@next/bundle-analyzer": "^15.1.2",
"@next/mdx": "^15.1.2",
"@prisma/client": "^6.0.1",
"@prisma/extension-accelerate": "^1.2.1",
@ -33,11 +32,9 @@
"@tanstack/react-query": "^5.62.9",
"@types/mdx": "^2.0.13",
"@vercel/analytics": "^1.4.1",
"@vercel/functions": "^1.5.0",
"@vercel/speed-insights": "^1.1.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"compression": "^1.7.5",
"date-fns": "^4.1.0",
"dompurify": "^3.2.3",
"lodash": "^4.17.21",

203
yarn.lock
View file

@ -427,13 +427,6 @@ __metadata:
languageName: node
linkType: hard
"@discoveryjs/json-ext@npm:0.5.7":
version: 0.5.7
resolution: "@discoveryjs/json-ext@npm:0.5.7"
checksum: 10c0/e10f1b02b78e4812646ddf289b7d9f2cb567d336c363b266bd50cd223cf3de7c2c74018d91cd2613041568397ef3a4a2b500aba588c6e5bd78c38374ba68f38c
languageName: node
linkType: hard
"@emnapi/runtime@npm:^1.2.0":
version: 1.3.1
resolution: "@emnapi/runtime@npm:1.3.1"
@ -1384,15 +1377,6 @@ __metadata:
languageName: node
linkType: hard
"@next/bundle-analyzer@npm:^15.1.2":
version: 15.1.2
resolution: "@next/bundle-analyzer@npm:15.1.2"
dependencies:
webpack-bundle-analyzer: "npm:4.10.1"
checksum: 10c0/bf1a1ef6554bd7c39b26cebe9a9e3c387d5874dc33278662732a269e106aa091255524e87c0fb43546918962450fcebee25a24c7c14d76afeb6c1268907b6246
languageName: node
linkType: hard
"@next/env@npm:15.1.2":
version: 15.1.2
resolution: "@next/env@npm:15.1.2"
@ -2283,13 +2267,6 @@ __metadata:
languageName: node
linkType: hard
"@polka/url@npm:^1.0.0-next.24":
version: 1.0.0-next.28
resolution: "@polka/url@npm:1.0.0-next.28"
checksum: 10c0/acc5ea62597e4da2fb42dbee02749d07f102ae7d6d2c966bf7e423c79cd65d1621da305af567e6e7c232f3b565e242d1ec932cbb3dcc0db1508d02e9a2cafa2e
languageName: node
linkType: hard
"@prisma/client@npm:^6.0.1":
version: 6.1.0
resolution: "@prisma/client@npm:6.1.0"
@ -4032,18 +4009,6 @@ __metadata:
languageName: node
linkType: hard
"@vercel/functions@npm:^1.5.0":
version: 1.5.2
resolution: "@vercel/functions@npm:1.5.2"
peerDependencies:
"@aws-sdk/credential-provider-web-identity": "*"
peerDependenciesMeta:
"@aws-sdk/credential-provider-web-identity":
optional: true
checksum: 10c0/9a9e64d6949fac13e73e56e95e68709216af31d7a14c0f8dd0f37f807e6fd9054fd11b142a535e41529584ee0320c2bed5d5644ab4ef561f83e84c79c932087d
languageName: node
linkType: hard
"@vercel/speed-insights@npm:^1.1.0":
version: 1.1.0
resolution: "@vercel/speed-insights@npm:1.1.0"
@ -4106,16 +4071,7 @@ __metadata:
languageName: node
linkType: hard
"acorn-walk@npm:^8.0.0":
version: 8.3.4
resolution: "acorn-walk@npm:8.3.4"
dependencies:
acorn: "npm:^8.11.0"
checksum: 10c0/76537ac5fb2c37a64560feaf3342023dadc086c46da57da363e64c6148dc21b57d49ace26f949e225063acb6fb441eabffd89f7a3066de5ad37ab3e328927c62
languageName: node
linkType: hard
"acorn@npm:^8.0.0, acorn@npm:^8.0.4, acorn@npm:^8.11.0, acorn@npm:^8.11.2, acorn@npm:^8.14.0, acorn@npm:^8.8.1, acorn@npm:^8.8.2, acorn@npm:^8.9.0":
"acorn@npm:^8.0.0, acorn@npm:^8.11.2, acorn@npm:^8.14.0, acorn@npm:^8.8.1, acorn@npm:^8.8.2, acorn@npm:^8.9.0":
version: 8.14.0
resolution: "acorn@npm:8.14.0"
bin:
@ -5077,13 +5033,6 @@ __metadata:
languageName: node
linkType: hard
"commander@npm:^7.2.0":
version: 7.2.0
resolution: "commander@npm:7.2.0"
checksum: 10c0/8d690ff13b0356df7e0ebbe6c59b4712f754f4b724d4f473d3cc5b3fdcf978e3a5dc3078717858a2ceb50b0f84d0660a7f22a96cdc50fb877d0c9bb31593d23a
languageName: node
linkType: hard
"commander@npm:^8.3.0":
version: 8.3.0
resolution: "commander@npm:8.3.0"
@ -5098,30 +5047,6 @@ __metadata:
languageName: node
linkType: hard
"compressible@npm:~2.0.18":
version: 2.0.18
resolution: "compressible@npm:2.0.18"
dependencies:
mime-db: "npm:>= 1.43.0 < 2"
checksum: 10c0/8a03712bc9f5b9fe530cc5a79e164e665550d5171a64575d7dcf3e0395d7b4afa2d79ab176c61b5b596e28228b350dd07c1a2a6ead12fd81d1b6cd632af2fef7
languageName: node
linkType: hard
"compression@npm:^1.7.5":
version: 1.7.5
resolution: "compression@npm:1.7.5"
dependencies:
bytes: "npm:3.1.2"
compressible: "npm:~2.0.18"
debug: "npm:2.6.9"
negotiator: "npm:~0.6.4"
on-headers: "npm:~1.0.2"
safe-buffer: "npm:5.2.1"
vary: "npm:~1.1.2"
checksum: 10c0/35c9d2d57c86d8107eab5e637f2146fcefec8475a2ff3e162f5eb0982ff856d385fb5d8c9823c3d50e075f2d9304bc622dac3df27bfef0355309c0a5307861c5
languageName: node
linkType: hard
"concat-map@npm:0.0.1":
version: 0.0.1
resolution: "concat-map@npm:0.0.1"
@ -5311,13 +5236,6 @@ __metadata:
languageName: node
linkType: hard
"debounce@npm:^1.2.1":
version: 1.2.1
resolution: "debounce@npm:1.2.1"
checksum: 10c0/6c9320aa0973fc42050814621a7a8a78146c1975799b5b3cc1becf1f77ba9a5aa583987884230da0842a03f385def452fad5d60db97c3d1c8b824e38a8edf500
languageName: node
linkType: hard
"debug@npm:2.6.9":
version: 2.6.9
resolution: "debug@npm:2.6.9"
@ -5618,13 +5536,6 @@ __metadata:
languageName: node
linkType: hard
"duplexer@npm:^0.1.2":
version: 0.1.2
resolution: "duplexer@npm:0.1.2"
checksum: 10c0/c57bcd4bdf7e623abab2df43a7b5b23d18152154529d166c1e0da6bee341d84c432d157d7e97b32fecb1bf3a8b8857dd85ed81a915789f550637ed25b8e64fc2
languageName: node
linkType: hard
"eastasianwidth@npm:^0.2.0":
version: 0.2.0
resolution: "eastasianwidth@npm:0.2.0"
@ -7234,15 +7145,6 @@ __metadata:
languageName: node
linkType: hard
"gzip-size@npm:^6.0.0":
version: 6.0.0
resolution: "gzip-size@npm:6.0.0"
dependencies:
duplexer: "npm:^0.1.2"
checksum: 10c0/4ccb924626c82125897a997d1c84f2377846a6ef57fbee38f7c0e6b41387fba4d00422274440747b58008b5d60114bac2349c2908e9aba55188345281af40a3f
languageName: node
linkType: hard
"has-bigints@npm:^1.0.2":
version: 1.1.0
resolution: "has-bigints@npm:1.1.0"
@ -7603,13 +7505,6 @@ __metadata:
languageName: node
linkType: hard
"html-escaper@npm:^2.0.2":
version: 2.0.2
resolution: "html-escaper@npm:2.0.2"
checksum: 10c0/208e8a12de1a6569edbb14544f4567e6ce8ecc30b9394fcaa4e7bb1e60c12a7c9a1ed27e31290817157e8626f3a4f29e76c8747030822eb84a6abb15c255f0a0
languageName: node
linkType: hard
"html-void-elements@npm:^3.0.0":
version: 3.0.0
resolution: "html-void-elements@npm:3.0.0"
@ -9471,13 +9366,6 @@ __metadata:
languageName: node
linkType: hard
"mime-db@npm:>= 1.43.0 < 2":
version: 1.53.0
resolution: "mime-db@npm:1.53.0"
checksum: 10c0/1dcc37ba8ed5d1c179f5c6f0837e8db19371d5f2ea3690c3c2f3fa8c3858f976851d3460b172b4dee78ebd606762cbb407aa398545fbacd539e519f858cd7bf4
languageName: node
linkType: hard
"mime-types@npm:^2.1.12, mime-types@npm:~2.1.24, mime-types@npm:~2.1.34":
version: 2.1.35
resolution: "mime-types@npm:2.1.35"
@ -9695,13 +9583,6 @@ __metadata:
languageName: node
linkType: hard
"mrmime@npm:^2.0.0":
version: 2.0.0
resolution: "mrmime@npm:2.0.0"
checksum: 10c0/312b35ed288986aec90955410b21ed7427fd1e4ee318cb5fc18765c8d029eeded9444faa46589e5b1ed6b35fb2054a802ac8dcb917ddf6b3e189cb3bf11a965c
languageName: node
linkType: hard
"ms@npm:2.0.0":
version: 2.0.0
resolution: "ms@npm:2.0.0"
@ -9757,13 +9638,6 @@ __metadata:
languageName: node
linkType: hard
"negotiator@npm:~0.6.4":
version: 0.6.4
resolution: "negotiator@npm:0.6.4"
checksum: 10c0/3e677139c7fb7628a6f36335bf11a885a62c21d5390204590a1a214a5631fcbe5ea74ef6a610b60afe84b4d975cbe0566a23f20ee17c77c73e74b80032108dea
languageName: node
linkType: hard
"netmask@npm:^2.0.2":
version: 2.0.2
resolution: "netmask@npm:2.0.2"
@ -10055,13 +9929,6 @@ __metadata:
languageName: node
linkType: hard
"on-headers@npm:~1.0.2":
version: 1.0.2
resolution: "on-headers@npm:1.0.2"
checksum: 10c0/f649e65c197bf31505a4c0444875db0258e198292f34b884d73c2f751e91792ef96bb5cf89aa0f4fecc2e4dc662461dda606b1274b0e564f539cae5d2f5fc32f
languageName: node
linkType: hard
"once@npm:^1.3.0, once@npm:^1.3.1, once@npm:^1.4.0":
version: 1.4.0
resolution: "once@npm:1.4.0"
@ -10098,15 +9965,6 @@ __metadata:
languageName: node
linkType: hard
"opener@npm:^1.5.2":
version: 1.5.2
resolution: "opener@npm:1.5.2"
bin:
opener: bin/opener-bin.js
checksum: 10c0/dd56256ab0cf796585617bc28e06e058adf09211781e70b264c76a1dbe16e90f868c974e5bf5309c93469157c7d14b89c35dc53fe7293b0e40b4d2f92073bc79
languageName: node
linkType: hard
"optionator@npm:^0.9.3":
version: 0.9.4
resolution: "optionator@npm:0.9.4"
@ -11916,17 +11774,6 @@ __metadata:
languageName: node
linkType: hard
"sirv@npm:^2.0.3":
version: 2.0.4
resolution: "sirv@npm:2.0.4"
dependencies:
"@polka/url": "npm:^1.0.0-next.24"
mrmime: "npm:^2.0.0"
totalist: "npm:^3.0.0"
checksum: 10c0/68f8ee857f6a9415e9c07a1f31c7c561df8d5f1b1ba79bee3de583fa37da8718def5309f6b1c6e2c3ef77de45d74f5e49efc7959214443aa92d42e9c99180a4e
languageName: node
linkType: hard
"smart-buffer@npm:^4.2.0":
version: 4.2.0
resolution: "smart-buffer@npm:4.2.0"
@ -12508,7 +12355,6 @@ __metadata:
"@mdx-js/loader": "npm:^3.1.0"
"@mdx-js/react": "npm:^3.1.0"
"@microsoft/eslint-formatter-sarif": "npm:^3.1.0"
"@next/bundle-analyzer": "npm:^15.1.2"
"@next/eslint-plugin-next": "npm:15.1.2"
"@next/mdx": "npm:^15.1.2"
"@prisma/client": "npm:^6.0.1"
@ -12535,13 +12381,11 @@ __metadata:
"@typescript-eslint/eslint-plugin": "npm:^8.18.2"
"@typescript-eslint/parser": "npm:^8.18.1"
"@vercel/analytics": "npm:^1.4.1"
"@vercel/functions": "npm:^1.5.0"
"@vercel/speed-insights": "npm:^1.1.0"
autoprefixer: "npm:^10.4.20"
babel-plugin-react-compiler: "npm:^19.0.0-beta-201e55d-20241215"
class-variance-authority: "npm:^0.7.1"
clsx: "npm:^2.1.1"
compression: "npm:^1.7.5"
date-fns: "npm:^4.1.0"
dompurify: "npm:^3.2.3"
eslint: "npm:^9.16.0"
@ -12655,13 +12499,6 @@ __metadata:
languageName: node
linkType: hard
"totalist@npm:^3.0.0":
version: 3.0.1
resolution: "totalist@npm:3.0.1"
checksum: 10c0/4bb1fadb69c3edbef91c73ebef9d25b33bbf69afe1e37ce544d5f7d13854cda15e47132f3e0dc4cafe300ddb8578c77c50a65004d8b6e97e77934a69aa924863
languageName: node
linkType: hard
"tr46@npm:~0.0.3":
version: 0.0.3
resolution: "tr46@npm:0.0.3"
@ -13317,29 +13154,6 @@ __metadata:
languageName: node
linkType: hard
"webpack-bundle-analyzer@npm:4.10.1":
version: 4.10.1
resolution: "webpack-bundle-analyzer@npm:4.10.1"
dependencies:
"@discoveryjs/json-ext": "npm:0.5.7"
acorn: "npm:^8.0.4"
acorn-walk: "npm:^8.0.0"
commander: "npm:^7.2.0"
debounce: "npm:^1.2.1"
escape-string-regexp: "npm:^4.0.0"
gzip-size: "npm:^6.0.0"
html-escaper: "npm:^2.0.2"
is-plain-object: "npm:^5.0.0"
opener: "npm:^1.5.2"
picocolors: "npm:^1.0.0"
sirv: "npm:^2.0.3"
ws: "npm:^7.3.1"
bin:
webpack-bundle-analyzer: lib/bin/analyzer.js
checksum: 10c0/6a94c8f6aa03296fb2eb00d6ad3b27bd5c551590fd253772bc61debf3177414d42701014079d4f85c74ba1ca685ae9f0cb4063812b58c21f294d108e9908e5cd
languageName: node
linkType: hard
"webpack-sources@npm:^3.2.3":
version: 3.2.3
resolution: "webpack-sources@npm:3.2.3"
@ -13482,21 +13296,6 @@ __metadata:
languageName: node
linkType: hard
"ws@npm:^7.3.1":
version: 7.5.10
resolution: "ws@npm:7.5.10"
peerDependencies:
bufferutil: ^4.0.1
utf-8-validate: ^5.0.2
peerDependenciesMeta:
bufferutil:
optional: true
utf-8-validate:
optional: true
checksum: 10c0/bd7d5f4aaf04fae7960c23dcb6c6375d525e00f795dd20b9385902bd008c40a94d3db3ce97d878acc7573df852056ca546328b27b39f47609f80fb22a0a9b61d
languageName: node
linkType: hard
"ws@npm:^8.18.0":
version: 8.18.0
resolution: "ws@npm:8.18.0"