Skip to content

Commit ebbf5f0

Browse files
committed
change to sim
1 parent 3294ec6 commit ebbf5f0

File tree

2 files changed

+16
-29
lines changed

2 files changed

+16
-29
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Dune Echo Proxy
1+
# Dune Sim Proxy
22

3-
This repo hosts a one-click-deploy Cloudflare worker that proxies requests to Dune Echo. The proxy will allow you to keep your API key
3+
This repo hosts a one-click-deploy Cloudflare worker that proxies requests to Dune Sim. The proxy will allow you to keep your API key
44
hidden from public requests made by clients. You will need both a [Dune](https://dune.com) account and a [Cloudflare](https://cloudflare.com) account to deploy this. Dune offers 10RPS for free, and Cloudflare workers can execute 100k invocations each day for free. Most projects can easily get started within these free tiers.
55

66
# Setup
@@ -26,8 +26,7 @@ You can now use your worker URL as an the base Dune API endpoint in all SDK and
2626

2727
# Additional Security Steps
2828
This implementation is intentionally left in a less-than-ideal security state to facilitate easy deployment by anyone. If you would like to
29-
lock down your Dune Echo Proxy further, consider the following steps after you have successfully deployed the worker:
30-
29+
lock down your Dune Sim Proxy further, consider the following steps after you have successfully deployed the worker:
3130

3231
* Update the `Access-Control-Allow-Origin` header by adding a new variable with the key name `CORS_ALLOW_ORIGIN` to contain the host that your requests are coming from (usually your client application). For example, if you wanted to allow requests from `https://example.com`, you would change the header to `https://example.com`. To support multiple domains, set `CORS_ALLOW_ORIGIN` to a comma separated list of domains (e.g. `https://example.com,https://beta.example.com`).
33-
* [Cloudflare Web Application Firewall (WAF)](https://www.cloudflare.com/lp/ppc/waf-x/) - You can configure the WAF to inspect requests and allow/deny based on your own business logic.
32+
* [Cloudflare Web Application Firewall (WAF)](https://www.cloudflare.com/lp/ppc/waf-x/) - You can configure the WAF to inspect requests and allow/deny based on your own business logic.

src/index.ts

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ interface Env {
55

66
export default {
77
async fetch(request: Request, env: Env) {
8-
98
// If the request is an OPTIONS request, return a 200 response with permissive CORS headers
109
// This is required for the Dune Echo Proxy to work from the browser and arbitrary origins
1110
// If you wish to restrict the origins that can access your Dune Echo Proxy, you can do so by
@@ -15,18 +14,18 @@ export default {
1514
// originated from one of the domains in the `CORS_ALLOW_ORIGIN` environment variable.
1615
const supportedDomains = env.CORS_ALLOW_ORIGIN?.split(',');
1716
const headers = {
18-
"Access-Control-Allow-Methods": "GET, HEAD, POST, PUT, OPTIONS",
19-
"Access-Control-Allow-Headers": "*",
20-
"Access-Control-Allow-Origin": supportedDomains
17+
'Access-Control-Allow-Methods': 'GET, HEAD, POST, PUT, OPTIONS',
18+
'Access-Control-Allow-Headers': '*',
19+
'Access-Control-Allow-Origin': supportedDomains
2120
? request.headers.get('Origin')
2221
? supportedDomains.includes(request.headers.get('Origin')!)
2322
? request.headers.get('Origin')!
2423
: undefined
2524
: undefined
26-
: '*'
25+
: '*',
2726
};
2827

29-
if (request.method === "OPTIONS") {
28+
if (request.method === 'OPTIONS') {
3029
return new Response(null, {
3130
status: 200,
3231
headers: headers as Record<string, string>,
@@ -35,25 +34,14 @@ export default {
3534

3635
const url = new URL(request.url);
3736

38-
// Return early if path does not start with /api/echo
39-
if (!url.pathname.startsWith("/api/echo")) {
40-
return new Response(null, {
41-
status: 404,
42-
headers: headers as Record<string, string>,
43-
});
44-
}
45-
4637
// Clone the request to modify headers
47-
const req = new Request(
48-
`https://api.dune.com${url.pathname}${url.search}`,
49-
{
50-
...request,
51-
headers: new Headers({
52-
...Object.fromEntries(request.headers.entries()),
53-
'x-dune-api-key': env.DUNE_API_KEY
54-
})
55-
}
56-
);
38+
const req = new Request(`https://api.sim.dune.com${url.pathname}${url.search}`, {
39+
...request,
40+
headers: new Headers({
41+
...Object.fromEntries(request.headers.entries()),
42+
'x-dune-api-key': env.DUNE_API_KEY,
43+
}),
44+
});
5745

5846
return fetch(req);
5947
},

0 commit comments

Comments
 (0)