This repository has been archived by the owner on Oct 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ant.config.ts
91 lines (86 loc) · 2.46 KB
/
ant.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* Bruh, using the {@link defineConfig} helper makes {@link loadConfig} take so much longer!!
* (JITI has to just-in-time compile __ALL__ the TypeScript)
* import { defineConfig } from 'peterportal-api-sst'
* export default defineConfig({ ... })
*/
import type { AntConfig, defineConfig } from "ant-stack/config";
import type { loadConfig } from "unconfig";
import env from "./env";
import {
Effect,
ManagedPolicy,
PolicyDocument,
PolicyStatement,
ServicePrincipal,
} from "aws-cdk-lib/aws-iam";
/**
* @see https://github.com/evanw/esbuild/issues/1921#issuecomment-1491470829
*/
const js = `\
import * as path from 'path';
import { fileURLToPath } from 'url';
import { createRequire as topLevelCreateRequire } from 'module';
const require = topLevelCreateRequire(import.meta.url);
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
`;
export const inDir = "./src";
export const outDir = "./dist";
export const entryFileName = "index";
/**
* Just using types is a lot faster!!
*/
const config: AntConfig = {
packageManager: "pnpm",
port: 8080,
aws: {
id: "peterportal-api-next",
zoneName: "peterportal.org",
routeRolePropsMapping: {
"v1-rest-websoc": {
assumedBy: new ServicePrincipal("lambda.amazonaws.com"),
managedPolicies: [
ManagedPolicy.fromAwsManagedPolicyName("service-role/AWSLambdaBasicExecutionRole"),
],
inlinePolicies: {
lambdaInvokePolicy: new PolicyDocument({
statements: [
new PolicyStatement({
effect: Effect.ALLOW,
resources: [
`arn:aws:lambda:${process.env.AWS_REGION}:${process.env.ACCOUNT_ID}:function:peterportal-api-next-services-prod-websoc-proxy-function`,
],
actions: ["lambda:InvokeFunction"],
}),
],
}),
},
},
},
},
env,
directory: "apps/api",
esbuild: {
entryPoints: [`${inDir}/${entryFileName}.ts`],
external: ["@aws-sdk/client-lambda"],
outdir: outDir,
platform: "node",
format: "esm",
target: "esnext",
bundle: true,
minify: true,
assetNames: "[name]",
loader: {
".env": "copy",
},
banner: { js },
},
runtime: {
entryFile: `${entryFileName}.js`,
entryHandlersName: "InternalHandlers",
lambdaCoreFile: "lambda-core.js",
nodeRuntimeFile: "lambda-node-runtime.js",
},
};
export default config;