-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
65 lines (62 loc) · 1.47 KB
/
index.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
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
// https://github.com/markusahlstrand/cloudworker-proxy
const Proxy = require("edge-proxy");
import index_html from "./index.html";
import simple_css from "./simple.css.txt";
const config = [
{
handlerName: "rateLimit",
options: {
limit: 1000, // The default allowed calls
scope: "default",
type: "IP", // Anything except IP will sum up all calls
},
},
{
handlerName: "cors",
options: {
allowedOrigins: ["*"],
allowedMethods: ["GET", "PUT", "POST", "DELETE", "HEAD", "OPTIONS"],
allowCredentials: true,
allowedHeaders: ["*"],
allowedExposeHeaders: ["X-Amz-Version-Id", "ETag"],
maxAge: 600,
optionsSuccessStatus: 204,
terminatePreflight: false,
},
},
{
handlerName: "s3",
path: "/s3-demo/:file*",
method: ["PUT", "GET", "DELETE"],
options: {
region: "eu-central-1",
accessKeyId: S3_KEY_ID,
secretAccessKey: S3_ACCESS_KEY,
bucket: "mps3-demo",
enableBucketOperations: true,
},
},
{
handlerName: "response",
path: "/simple.css",
options: {
headers: {
"Content-Type": "text/css; charset=utf-8",
},
body: simple_css,
},
},
{
handlerName: "response",
options: {
headers: {
"Content-Type": "text/html; charset=utf-8",
},
body: index_html,
},
},
];
const proxy = new Proxy(config);
addEventListener("fetch", (event) => {
event.respondWith(proxy.resolve(event));
});