-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #987 from CodeForAfrica/chore/climatemappedafrica_…
…static_build @/climatemappedafrica Static Build
- Loading branch information
Showing
14 changed files
with
1,985 additions
and
1,678 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# dependencies | ||
node_modules | ||
.pnp | ||
.pnp.js | ||
.pnpm-debug.log | ||
|
||
# typescript | ||
dist/ | ||
|
||
# testing | ||
coverage | ||
|
||
# next.js | ||
.next/ | ||
out/ | ||
|
||
# payload | ||
build/ | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Vercel | ||
.vercel | ||
.now | ||
|
||
# turbo | ||
.turbo | ||
test-results/ | ||
playwright-report/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
"version": "0.0.3", | ||
"private": true, | ||
"author": "Code for Africa <[email protected]>", | ||
"description": "Climate Mapped Africa ", | ||
"description": "ClimateMapped Africa", | ||
"keywords": [ | ||
"climatemappedafrica", | ||
"next", | ||
|
@@ -65,7 +65,6 @@ | |
"next": "catalog:", | ||
"next-images": "catalog:", | ||
"next-seo": "catalog:", | ||
"nodemailer-sendgrid": "catalog:", | ||
"papaparse": "catalog:", | ||
"payload": "catalog:", | ||
"plaiceholder": "catalog:", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,18 +2,29 @@ import path from "path"; | |
import { spawn } from "child_process"; | ||
import express from "express"; | ||
import next from "next"; | ||
import nodemailerSendgrid from "nodemailer-sendgrid"; | ||
import payload from "payload"; | ||
import { Payload } from "payload/dist/payload"; | ||
import { loadEnvConfig } from "@next/env"; | ||
import type { Payload } from "payload/dist/payload"; | ||
|
||
// TODO(kilemensi): Figure out why alias "@/climatemappedafrica" doesn't work here | ||
import { getClient } from "./src/lib/payload/payload-client"; | ||
|
||
const projectDir = process.cwd(); | ||
loadEnvConfig(projectDir); | ||
|
||
const dev = process.env.NODE_ENV !== "production"; | ||
const hostname = process.env.NEXT_HOSTNAME || "localhost"; | ||
const port = parseInt(process.env.PORT || "3000", 10); | ||
const sendGridAPIKey = process.env.SENDGRID_API_KEY; | ||
// TODO(kilemensi): Migrate to SMTP email setup instead of SendGrid specific | ||
const smtpAuthPass = process.env.SMTP_PASS || process.env.SENDGRID_API_KEY; | ||
const smtpFromName = | ||
process.env.SMTP_FROM_NAME || | ||
process.env.SENDGRID_FROM_NAME || | ||
"ClimateMapped Africa CMS"; | ||
const smtpFromAddress = | ||
process.env.SMTP_FROM_ADDRESS || | ||
process.env.SENDGRID_FROM_EMAIL || | ||
"[email protected]"; | ||
const smtpPort = Number(process.env.SMTP_PORT || 587); | ||
|
||
if (!process.env.NEXT_MANUAL_SIG_HANDLE) { | ||
process.on("SIGTERM", () => process.exit(0)); | ||
|
@@ -25,24 +36,30 @@ const app = express(); | |
const start = async (): Promise<void> => { | ||
let localPayload: Payload; | ||
try { | ||
localPayload = await payload.init({ | ||
...(sendGridAPIKey | ||
localPayload = await getClient({ | ||
...(smtpAuthPass | ||
? { | ||
email: { | ||
transportOptions: nodemailerSendgrid({ | ||
apiKey: sendGridAPIKey, | ||
}), | ||
fromName: | ||
process.env.SENDGRID_FROM_NAME || "ClimateMapped Africa CMS", | ||
fromAddress: | ||
process.env.SENDGRID_FROM_EMAIL || "[email protected]", | ||
transportOptions: { | ||
auth: { | ||
user: process.env.SMTP_USER || "apikey", | ||
apiKey: smtpAuthPass, | ||
}, | ||
host: process.env.SMTP_HOST || "smtp.sendgrid.net", | ||
port: smtpPort, | ||
secure: smtpPort === 465, // true for port 465, false (the default) for 587 and others | ||
}, | ||
fromName: smtpFromName, | ||
fromAddress: smtpFromAddress, | ||
}, | ||
} | ||
: undefined), | ||
secret: process.env.PAYLOAD_SECRET, | ||
express: app, | ||
local: false, | ||
onInit: (initPayload) => { | ||
initPayload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`); | ||
initPayload.logger.info( | ||
`Payload Admin URL: ${initPayload.getAdminURL()}`, | ||
); | ||
}, | ||
}); | ||
} catch (e: any) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
apps/climatemappedafrica/src/components/HURUmap/Tutorial/TutorialStep/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
export { getPageStaticPaths, getPageStaticProps } from "./local"; | ||
|
||
export { getPageServerSideProps } from "./local"; | ||
export default undefined; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
import { payload } from "@/climatemappedafrica/lib"; | ||
import { getPageProps } from "@/climatemappedafrica/lib/data/common"; | ||
import { | ||
getPagePaths, | ||
getPageProps, | ||
} from "@/climatemappedafrica/lib/data/common"; | ||
import payload from "@/climatemappedafrica/lib/payload"; | ||
|
||
export const api = payload; | ||
|
||
export async function getPageServerSideProps(context) { | ||
export async function getPageStaticPaths() { | ||
return getPagePaths(api); | ||
} | ||
|
||
export async function getPageStaticProps(context) { | ||
const props = await getPageProps(api, context); | ||
|
||
// TODO(kilemensi): We need to differentiate 404 from server errors (5xx) | ||
// https://nextjs.org/docs/14/pages/building-your-application/data-fetching/incremental-static-regeneration#error-handling-and-revalidation | ||
if (!props) { | ||
return { notFound: true }; | ||
} | ||
return { | ||
props, | ||
revalidate: 120, // in seconds | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
apps/climatemappedafrica/src/lib/payload/payload-client.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// TODO(kilemensi): Need to update eslint to handle globalThis but we should | ||
// do that when upgrading Next.js | ||
/* eslint no-undef:0 */ | ||
import { loadEnvConfig } from "@next/env"; | ||
import payload from "payload"; | ||
|
||
const projectDir = process.cwd(); | ||
loadEnvConfig(projectDir); | ||
|
||
let cached = globalThis.payload; | ||
|
||
if (!cached) { | ||
globalThis.payload = { client: null, promise: null }; | ||
cached = globalThis.payload; | ||
} | ||
|
||
export async function getClient(options) { | ||
if (cached.client) { | ||
return cached.client; | ||
} | ||
|
||
if (!cached.promise) { | ||
cached.promise = payload.init({ | ||
// https://payloadcms.com/docs/local-api/overview#nextjs-conflict-with-local-api | ||
local: !options?.express, | ||
secret: process.env.PAYLOAD_SECRET, | ||
...options, | ||
}); | ||
} | ||
try { | ||
cached.client = await cached.promise; | ||
} catch (e) { | ||
cached.promise = null; | ||
throw e; | ||
} | ||
return cached.client; | ||
} | ||
|
||
export default undefined; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.