-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
149 additions
and
44 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
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,9 +1,33 @@ | ||
import type { Prisma, PrismaClient as PrismaClientType } from '@prisma/client'; | ||
import { PrismaClient } from '@prisma/client'; | ||
import { Config } from 'sst/node/config'; | ||
import memoize from 'memoizee'; | ||
import { GetSecretValueCommand, SecretsManagerClient } from '@aws-sdk/client-secrets-manager'; | ||
import { GetSecretValueCommand, SecretsManagerClient } from '@aws-sdk/client-secrets-manager' | ||
import type { Prisma, PrismaClient as PrismaClientType } from '@prisma/client' | ||
import { PrismaClient } from '@prisma/client' | ||
import memoize from 'memoizee' | ||
import { Config } from 'sst/node/config' | ||
|
||
export const getPrisma = memoize(async (opts?: Prisma.PrismaClientOptions): Promise<PrismaClientType> => { | ||
return new PrismaClient(opts); | ||
}); | ||
const databaseUrl = await getDatabaseUrl() | ||
opts = opts || {} | ||
opts.datasourceUrl ||= databaseUrl | ||
|
||
return new PrismaClient(opts) | ||
}) | ||
|
||
export const getDatabaseUrl = async (): Promise<string> => { | ||
let databaseUrl = process.env.DATABASE_URL | ||
if (process.env.USE_DB_CONFIG !== 'true' && databaseUrl) return databaseUrl | ||
|
||
// load database secret | ||
const secretArn = Config.DB_SECRET_ARN | ||
const client = new SecretsManagerClient({}) | ||
const req = new GetSecretValueCommand({ SecretId: secretArn }) | ||
const res = await client.send(req) | ||
if (!res.SecretString) throw new Error(`Missing secretString in ${secretArn}`) | ||
const secrets = JSON.parse(res.SecretString) as any | ||
const { host, username, password, port, dbname } = secrets | ||
if (!host) throw new Error('Missing host in secrets') | ||
|
||
// construct database url | ||
databaseUrl = `postgresql://${username}:${password}@${host}:${port}/${dbname}` | ||
|
||
return databaseUrl | ||
} |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Function, StackContext } from 'sst/constructs' | ||
|
||
export function Iam({ stack }: StackContext) { | ||
// default role for lambda functions | ||
// so we don't end up with >1000 roles | ||
// HACK to make a role that inherits permissions/config from the app | ||
// 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', | ||
}) | ||
|
||
return { | ||
defaultLambdaRole: placeholderFn.role!, | ||
} | ||
} |
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
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,4 +1,48 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = {}; | ||
const nextConfig = { | ||
transpilePackages: ['@common'], | ||
|
||
export default nextConfig; | ||
// for open-next output | ||
outputFileTracingRoot: path.join(__dirname, '../'), | ||
// don't include dev deps in the deployed bundle | ||
outputFileTracingExcludes: { | ||
'*': [ | ||
'./**/.prisma/client/libquery_engine-darwin*', // prisma mac binary | ||
'./**/@swc/core-linux-x64-gnu*', | ||
'./**/@swc/core-linux-x64-musl*', | ||
'./**/@esbuild*', | ||
'./**/webpack*', | ||
'./**/rollup*', | ||
'./**/terser*', | ||
'./**/sharp*', | ||
], | ||
}, | ||
|
||
images: { | ||
remotePatterns: [ | ||
{ | ||
protocol: 'https', | ||
hostname: '**', | ||
port: '', | ||
pathname: '**', | ||
}, | ||
{ | ||
protocol: 'http', | ||
hostname: 'localhost', | ||
port: '6001', | ||
pathname: '**', | ||
}, | ||
], | ||
minimumCacheTTL: 86400 * 365, // cache optimized images for a long time | ||
}, | ||
|
||
// https://docs.sst.dev/constructs/NextjsSite#source-maps | ||
webpack: (config, options) => { | ||
if (!options.dev) { | ||
config.devtool = 'source-map' | ||
} | ||
return config | ||
}, | ||
} | ||
|
||
export default nextConfig |