Skip to content

Commit 46f703a

Browse files
author
sahil kapase
committed
feat: optimize repo for AWS Amplify deployment (#349)
- Add amplify.yml with pnpm-based build pipeline and caching configuration - Set Next.js output to standalone for AWS runtime compatibility - Port Vercel caching headers to Next.js headers() config for Amplify - Add long-term caching for static assets and _next/static files - Configure build artifacts and cache paths for optimal Amplify performance This addresses the expensive Vercel hosting by preparing the codebase for seamless migration to AWS Amplify with proper caching strategies and build optimizations.
1 parent 12ffbbb commit 46f703a

2 files changed

Lines changed: 98 additions & 0 deletions

File tree

amplify.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
version: 1
2+
applications:
3+
- appRoot: .
4+
frontend:
5+
phases:
6+
preBuild:
7+
commands:
8+
- corepack enable
9+
- corepack prepare pnpm@9.1.4 --activate
10+
- pnpm install --frozen-lockfile
11+
build:
12+
commands:
13+
- pnpm build
14+
artifacts:
15+
baseDirectory: .next
16+
files:
17+
- '**/*'
18+
cache:
19+
paths:
20+
- node_modules/**
21+
- .next/cache/**
22+
customHeaders:
23+
- pattern: /_next/static/*
24+
headers:
25+
- key: Cache-Control
26+
value: public, max-age=31536000, immutable
27+
- pattern: /public/*
28+
headers:
29+
- key: Cache-Control
30+
value: public, max-age=604800, stale-while-revalidate=86400
31+
- pattern: /api/upcoming-papers
32+
headers:
33+
- key: Cache-Control
34+
value: s-maxage=60, stale-while-revalidate=120
35+
- pattern: /api/papers
36+
headers:
37+
- key: Cache-Control
38+
value: s-maxage=60, stale-while-revalidate=120
39+
- pattern: /api/selected-papers
40+
headers:
41+
- key: Cache-Control
42+
value: s-maxage=60, stale-while-revalidate=120
43+
- pattern: /api/related-subject
44+
headers:
45+
- key: Cache-Control
46+
value: s-maxage=60, stale-while-revalidate=120
47+
- pattern: /api/course-list
48+
headers:
49+
- key: Cache-Control
50+
value: s-maxage=60, stale-while-revalidate=120
51+

next.config.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,56 @@ await import("./src/env.js");
77
/** @type {import("next").NextConfig} */
88
const config = {
99
swcMinify: false,
10+
output: "standalone",
1011
images: {
1112
domains: ["res.cloudinary.com"],
1213
},
14+
async headers() {
15+
return [
16+
{
17+
source: "/api/upcoming-papers",
18+
headers: [
19+
{ key: "Cache-Control", value: "s-maxage=60, stale-while-revalidate=120" },
20+
],
21+
},
22+
{
23+
source: "/api/papers",
24+
headers: [
25+
{ key: "Cache-Control", value: "s-maxage=60, stale-while-revalidate=120" },
26+
],
27+
},
28+
{
29+
source: "/api/selected-papers",
30+
headers: [
31+
{ key: "Cache-Control", value: "s-maxage=60, stale-while-revalidate=120" },
32+
],
33+
},
34+
{
35+
source: "/api/related-subject",
36+
headers: [
37+
{ key: "Cache-Control", value: "s-maxage=60, stale-while-revalidate=120" },
38+
],
39+
},
40+
{
41+
source: "/api/course-list",
42+
headers: [
43+
{ key: "Cache-Control", value: "s-maxage=60, stale-while-revalidate=120" },
44+
],
45+
},
46+
{
47+
source: "/_next/static/:path*",
48+
headers: [
49+
{ key: "Cache-Control", value: "public, max-age=31536000, immutable" },
50+
],
51+
},
52+
{
53+
source: "/:all*(css|js|png|jpg|jpeg|gif|webp|svg|ico|woff|woff2)",
54+
headers: [
55+
{ key: "Cache-Control", value: "public, max-age=604800, stale-while-revalidate=86400" },
56+
],
57+
},
58+
];
59+
},
1360
webpack: (config, options) => {
1461
config.resolve.alias.canvas = false;
1562
config.module.rules.push({

0 commit comments

Comments
 (0)