Skip to content

Commit

Permalink
fix open-next stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
revmischa committed Jul 2, 2024
1 parent 214ef90 commit f1e0b79
Show file tree
Hide file tree
Showing 8 changed files with 583 additions and 3,294 deletions.
1 change: 1 addition & 0 deletions backend/src/function/empty.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const handler = () => 'noop'
534 changes: 528 additions & 6 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion stacks/iam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function Iam({ stack }: StackContext) {
// by making an empty function
// more info: https://discord.com/channels/983865673656705025/1027663092957581383
const placeholderFn = new Function(stack, 'IamDefault', {
handler: 'backend/src/api/internalFunctions/empty.handler',
handler: 'backend/src/function/empty.handler',
})

return {
Expand Down
38 changes: 20 additions & 18 deletions stacks/web.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
import { NextjsSite, StackContext, use } from 'sst/constructs';
import { AppSyncApi } from './appSyncApi';
import { Auth } from './auth';
import { Dns } from './dns';
import { WEB_URL } from './config';
import { Secrets } from './secrets';
import { NextjsSite, StackContext, use } from 'sst/constructs'
import { AppSyncApi } from './appSyncApi'
import { Auth } from './auth'
import { Dns } from './dns'
import { IS_PRODUCTION, WEB_URL } from './config'
import { Secrets } from './secrets'

export function Web({ stack, app }: StackContext) {
const { userPool, webClient, cognitoDomainName } = use(Auth);
const { secrets, ...configSecrets } = use(Secrets);
const appSyncApi = use(AppSyncApi);
const dns = use(Dns);
const isLocal = app.local;
const { userPool, webClient, cognitoDomainName } = use(Auth)
const { secrets, ...configSecrets } = use(Secrets)
const appSyncApi = use(AppSyncApi)
const dns = use(Dns)
const isLocal = app.local

if (!isLocal && !process.env.SST_STAGE && !WEB_URL) {
console.warn(`Please set WEB_URL in .env.${app.stage} to the URL of your frontend site.`);
console.warn(`Please set WEB_URL in .env.${app.stage} to the URL of your frontend site.`)
}

const allSecrets = Object.values(configSecrets);
const allSecrets = Object.values(configSecrets)

// docs: https://docs.serverless-stack.com/constructs/NextjsSite
const frontendSite = new NextjsSite(stack, 'Web', {
const nextjsApp = new NextjsSite(stack, 'Web', {
path: 'web',
openNextVersion: '3.0.6',
bind: [...allSecrets],
runtime: 'nodejs20.x',
warm: IS_PRODUCTION ? 6 : 0,
customDomain: dns.domainName
? {
domainName: dns.domainName,
Expand All @@ -34,7 +36,7 @@ export function Web({ stack, app }: StackContext) {
comment: `NextJS distribution for ${app.name} (${app.stage})`,
},
},
memorySize: 1024,
memorySize: 1536,
environment: {
NEXTAUTH_SECRET: secrets.secretValueFromJson('AUTH_SECRET').toString(),
NEXTAUTH_URL: isLocal ? 'http://localhost:6001' : WEB_URL ?? 'https://set-me-in-.env',
Expand All @@ -45,9 +47,9 @@ export function Web({ stack, app }: StackContext) {
NEXT_PUBLIC_COGNITO_USER_POOL_ID: userPool.userPoolId,
NEXT_PUBLIC_COGNITO_DOMAIN_NAME: cognitoDomainName,
},
});
})

stack.addOutputs({
WebURL: frontendSite.customDomainUrl || frontendSite.url || 'unknown',
});
WebURL: nextjsApp.customDomainUrl || nextjsApp.url || 'unknown',
})
}
4 changes: 3 additions & 1 deletion web/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { resolve } from 'path'
const __dirname = resolve()
const projectRoot = resolve(__dirname, '../')
console.log('projectRoot', projectRoot)

/** @type {import('next').NextConfig} */
const nextConfig = {
transpilePackages: ['@common'],

experimental: {
// for open-next output
outputFileTracingRoot: resolve(__dirname, '../'),
outputFileTracingRoot: projectRoot,
// don't include dev deps in the deployed bundle
outputFileTracingExcludes: {
'*': [
Expand Down
29 changes: 29 additions & 0 deletions web/open-next.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { OpenNextConfig } from 'open-next/types/open-next.js'

// https://open-next.js.org/v3/config

const config = {
default: {
// This is the default server, similar to the server-function in open-next v2
// You don't have to provide the below, by default it will generate an output
// for normal lambda as in open-next v2
// override: {
// wrapper: 'aws-lambda-streaming', // This is necessary to enable lambda streaming
// },
},

// Below we define the functions that we want to deploy in a different server
// functions: {
// ssr: {
// routes: ["app/api/trpc/[trpc]/route"], // For app dir, you need to include route|page, no need to include layout or loading
// patterns: ["api/*"], // patterns needs to be in a cloudfront compatible format, this will be used to generate the output
// override: {
// wrapper: "aws-lambda-streaming",
// },
// experimentalBundledNextServer: true, // This enables the bundled next server which is faster and reduce the size of the server
// },
// },
} satisfies OpenNextConfig

export default config
export type Config = typeof config
1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"open-next": "^3.0.6",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"typescript": "^5"
Expand Down
Loading

0 comments on commit f1e0b79

Please sign in to comment.