-
Notifications
You must be signed in to change notification settings - Fork 0
/
sst.config.ts
74 lines (65 loc) · 1.68 KB
/
sst.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
import { existsSync, readFileSync } from 'fs';
import { parse as parseEnvironment } from 'dotenv';
import type { SSTConfig } from 'sst';
import type { StackContext } from 'sst/constructs';
import { Api, Function } from 'sst/constructs';
export const Relayer = ({ stack, app }: StackContext) => {
const environment = environmentFromStage(app.stage);
const handlerFunction = new Function(stack, 'relayer-func', {
handler: './lambda.handler',
timeout: '5 minutes',
runtime: 'nodejs20.x',
architecture: 'arm_64',
environment,
nodejs: { format: 'cjs' },
});
const relayer = new Api(stack, 'relayer-api', {
cors: {
allowOrigins: ['*'],
allowHeaders: ['Content-Type', 'Authorization'],
allowMethods: ['GET', 'POST'],
},
routes: {
'POST /send-reward': {
function: handlerFunction,
},
'POST /estimate-fee': {
function: handlerFunction,
},
'GET /keypair': {
function: handlerFunction,
},
},
});
stack.addOutputs({
relayerUrl: relayer.url,
});
};
const environmentFileMap: Record<string, string> = {
production: '.env.production',
staging: '.env.staging',
development: '.env.development',
};
const environmentFromStage = (stage: string): Record<string, string> => {
const envFile = environmentFileMap[stage] || environmentFileMap.development;
let environmentBuf: Buffer;
if (existsSync(envFile)) {
environmentBuf = readFileSync(envFile);
} else if (existsSync('.env')) {
environmentBuf = readFileSync('.env');
} else {
return {};
}
return parseEnvironment(environmentBuf);
};
export default {
config() {
return {
name: 'quickom-web3',
region: 'ap-south-1',
};
},
stacks(app) {
app.stack(Relayer);
},
} satisfies SSTConfig;