-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (34 loc) · 779 Bytes
/
index.js
File metadata and controls
41 lines (34 loc) · 779 Bytes
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
'use strict';
import url from 'url';
import app from '@architect/shared/app.js'; // eslint-disable-line import/no-unresolved
async function handler(event) {
const { host, rawPath: path, httpMethod, headers, queryStringParameters, body } = event;
const query = new url.URLSearchParams();
for (const k in queryStringParameters) {
const value = queryStringParameters[k];
value.split(', ').forEach((v) => {
query.append(k, v);
});
}
const rendered = await app.render({
host,
method: httpMethod,
headers,
path,
body,
query
});
if (rendered) {
return {
isBase64Encoded: false,
statusCode: rendered.status,
headers: rendered.headers,
body: rendered.body
};
}
return {
statusCode: 404,
body: 'Not Found'
};
}
export { handler };