-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambda.ts
64 lines (53 loc) · 1.53 KB
/
lambda.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
import serverlessExpress from 'aws-serverless-express'
import { Context } from 'aws-lambda'
import app from './app'
import { BuildService, OpensearchService } from './src/services'
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace NodeJS {
interface ProcessEnv {
TARGET_ENV: string
GSUITE_URL: string
}
}
}
const env = process.env.TARGET_ENV
const server = serverlessExpress.createServer(app)
export const handler = (event: any, context: Context) => {
if (env === 'local') {
if (event.headers) {
const auth = event.headers.Authorization
event.__auth = auth
delete event.multiValueHeaders
delete event.headers.Authorization
}
}
const result = serverlessExpress.proxy(server, event, context)
return result
}
export const build = async () => {
const todaysDate = new Date()
const currentYear = todaysDate.getFullYear()
const startYear = Number(process.env.BUILD_START_YEAR)
const results = []
const build = new BuildService()
for(let y=startYear; y<=currentYear; y++){
console.log(`Building ${y}`);
const out = await build.year(String(y));
results.push(out)
}
console.log(`Building Pages`);
const out = await build.pages();
results.push(out)
return results
}
export const reset = async () => {
const os = new OpensearchService()
const out = await os.delete()
return out.results.body
}
export const harvest = async () => {
const build = new BuildService()
const result = await build.harvest()
return result
}