Skip to content

Instantly share code, notes, and snippets.

@zzzarius
Created October 5, 2022 08:25
Show Gist options
  • Save zzzarius/45990c841be58319e94e7d5a83ccadc4 to your computer and use it in GitHub Desktop.
Save zzzarius/45990c841be58319e94e7d5a83ccadc4 to your computer and use it in GitHub Desktop.
Drop CORS for some resource (Deno server)
import { Application, Router } from "https://deno.land/x/oak/mod.ts";
const router = new Router();
router.get("/path/:file", async (context) => {
if (context?.params?.file) {
const data = await fetch(
`https://cdn.somedomain.com/js/${context?.params?.file}`,
);
console.log(data);
context.response.body = data.body;
}
});
const app = new Application();
app.use((ctx, next) => {
ctx.response.headers.set("Access-Control-Allow-Origin", "*");
return next();
});
app.use(router.routes());
app.use(router.allowedMethods());
await app.listen({ port: 8000 });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment