forked from scaleway/serverless-functions-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.js
31 lines (28 loc) · 833 Bytes
/
handler.js
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
import { pathToFileURL } from "url";
export function handle(event, context, callback) {
const response = {
statusCode: 201,
body: {
message: "function with promise",
},
headers: {
"Content-Type": "application/json",
},
};
return new Promise((resolve, reject) => {
const day = new Date().getDay();
let err = undefined;
if (day === 0 || day === 6) {
err = new Error("Weekend are for resting");
}
if (err) return reject(err);
return resolve(response);
});
}
/* Module was not imported but called directly, so we can test locally.
This will not be executed on Scaleway Functions */
if (import.meta.url === pathToFileURL(process.argv[1]).href) {
import("@scaleway/serverless-functions").then(scw_fnc_node => {
scw_fnc_node.serveHandler(handle, 8080);
});
}