Comments (6)
Why cant you use reply.send(stream)?
from fastify-cors.
I believe nothing it can do on our side.
Do not use reply.raw
directly since it bypass all logic we have.
Or do all the thing on your own if you really want to use reply.raw
.
from fastify-cors.
See the test i added to the PR #260 on how to do it correct.
from fastify-cors.
Any workaround?
upd: Use custom preHandler hook:
fastify.addHook('preHandler', corsPreHandler)
export const corsPreHandler = (req: FastifyRequest, res: FastifyReply, done: HookHandlerDoneFunction) => {
const blacklistedPaths = ['/page/:pageParam']
if (!blacklistedPaths.includes(req.routerPath)) {
const origin = req.headers.origin ?? ''
res.header('Access-Control-Allow-Origin', origin)
res.header('Access-Control-Allow-Methods', '*')
res.header('Access-Control-Allow-Headers', '*')
}
const isPreflight = /options/i.test(req.method)
if (isPreflight) {
return res.send()
}
done()
}
taken from SO
from fastify-cors.
stream.pipe(reply.raw)
bypasses all Fastify logic by using reply.raw
. Use return stream
in your route or reply.send(stream)
from fastify-cors.
Also worked when I did this:
reply
.type("application/json")
.header("Access-Control-Allow-Origin", "*")
.header("Content-Length", fs.statSync(filePath).size);
reply.raw.writeHead(200, reply.getHeaders());
return stream.pipe(reply.raw);
from fastify-cors.
Related Issues (20)
- doesnt' work with Typescript HOT 1
- Origin returns undefined HOT 14
- Latency when using a large JWT token HOT 7
- UnhandledPromiseRejectionWarning: AvvioError: Plugin must be a function or a promise HOT 1
- Allow the special `*` value in `array` in `origin` option HOT 3
- Setting for `Cache-Control` to allow preflight requests to be cached in CDNs HOT 1
- Error(s) in doc. HOT 1
- cacheControl default value is missing HOT 1
- AvvioError [Error]: Plugin did not start in time: '[object Promise]' HOT 2
- Support Private Network CORS HOT 8
- Options Request Returns 404 running in bun HOT 1
- Missing type declaration file for β@fastify/corsβ module HOT 2
- preflight 404 on prefixed index routes in nested/scopted cors setups
- Multiple @fastify/cors HOT 2
- Do not always define `Vary` header HOT 1
- `preHandler` called twice when rejecting CORS HOT 5
- Vary with dynamic config
- Credentials header is added regardless of origin HOT 2
- CORS Issue with Fastify and Socket.IO Configuration HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastify-cors.