-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
server-fastly.js
38 lines (33 loc) · 1.05 KB
/
server-fastly.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
// eslint-disable-next-line spaced-comment
/// <reference types="@fastly/js-compute" />
/*
* Copyright (c) 2022 RethinkDNS and its authors.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import "./core/fastly/config.js";
import { handleRequest } from "./core/doh.js";
import * as system from "./system.js";
import * as util from "./commons/util.js";
addEventListener("fetch", (event) => {
return event.respondWith(serveDoh(event));
});
/**
* @param {FetchEvent} event
* @returns {Response}
*/
async function serveDoh(event) {
// on Fastly, the network-context is only available in an event listener
// and so, publish system prepare from here instead of from main which
// runs in global-scope.
system.pub("prepare");
try {
await system.when("go");
return await handleRequest(event);
} catch (e) {
console.error("server", "serveDoh err", e);
return util.respond405();
}
}