-
Notifications
You must be signed in to change notification settings - Fork 14
/
functions-admin.ts
52 lines (47 loc) · 1.48 KB
/
functions-admin.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
import type { Request, Response, NextFunction } from "express"
import { NoodlParseServerResult } from "../parse"
import { deployFunctions } from "../function-deploy"
export async function routeFunctionsAdmin(
noodlServer: NoodlParseServerResult,
req: Request,
res: Response,
_next: NextFunction
) {
if (req.headers['x-parse-master-key'] !== noodlServer.options.masterKey) {
return res.status(401).json({
message: 'Not authorized'
})
}
if (req.headers['x-parse-application-id'] !== noodlServer.options.appId) {
return res.status(401).json({
message: 'Not authorized'
})
}
// Deploy a new version
if (req.method === 'POST' && req.url === "/functions-admin/deploy") {
if (!req.body || typeof req.body.deploy !== "string" || typeof req.body.runtime !== "string") {
return res.status(400).json({
message: 'Must supply deploy and runtime'
})
}
console.log('Uploading deploy...')
const { version } = await deployFunctions({
port: noodlServer.options.port,
appId: noodlServer.options.appId,
masterKey: noodlServer.options.masterKey,
runtime: req.body.runtime,
data: req.body.deploy
})
console.log('Upload completed, version: ' + version)
res.json({
status: 'success',
version
})
} else if (req.method === 'GET' && req.url === "/functions-admin/info") {
res.json({
version: '1.0'
})
} else res.status(400).json({
message: 'Function not supported'
})
}