Created
October 5, 2022 08:25
-
-
Save zzzarius/45990c841be58319e94e7d5a83ccadc4 to your computer and use it in GitHub Desktop.
Drop CORS for some resource (Deno server)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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