-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.ts
62 lines (51 loc) · 1.68 KB
/
config.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
import { get, options } from "./storage_handlers.ts";
import { documentation } from "./documentation.ts";
import { CreateProxyOptions, StorageHandler } from "./types.ts";
export const safeHandlers = new Map<
string,
StorageHandler
>([
["GET", get],
["HEAD", get],
["OPTIONS", options],
]);
export const safeMethods = new Set(["GET", "HEAD", "OPTIONS"]);
export const xmlheaders = { "content-type": "application/xml; charset=utf-8" };
export const corsheaders = new Headers([
["access-control-allow-origin", "*"],
[
"access-control-allow-methods",
"DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT",
],
]);
export const defaultSuffix = "core.windows.net";
export const buildConnectionString = (
{ account = "", key = "", suffix = defaultSuffix } = {},
): string =>
`AccountName=${account};AccountKey=${key};EndpointSuffix=${suffix};DefaultEndpointsProtocol=https;`;
export const containerPattern = new URLPattern({
pathname: "/:container([a-z][\\w-]+)/:path*",
});
const defaults = (env: Deno.Env): CreateProxyOptions => {
const account = env.get("azure_account") ?? "";
const key = env.get("azure_key") ?? "";
const _cont = env.get("azure_containers");
const containers = _cont && _cont.length > 4
? new Set<string>(JSON.parse(_cont))
: new Set<string>();
const suffix = env.get("azure_suffix") ?? defaultSuffix;
const handlers = safeHandlers;
const fallback = documentation({ account, containers, suffix, handlers });
return {
account,
key,
containers,
suffix,
handlers,
fallback,
};
};
export function config(options = {}): CreateProxyOptions {
const defaultOptions = defaults(Deno.env);
return { ...defaultOptions, ...options };
}