Comments (4)
Yeah I believe you are correct, but it would be good if you could get the specific section of the spec for this so we can align on the expectations. I did a cursory search and found this which I think is the right place. It has been a long time since I have looked at these and this doc is new to me.
Additionally I would say I am surprised this is broken. I don't remember any specific options
handling here and setHeader
is not an express api but comes directly from node. It might be worth checking with a reduced test case what the behavior is without express.
from express.
hello @yhojann-cl , can you detail what functions allowFor
and schemafor
are? What is the source code of these functions?
I'm guessing that maybe not using the function json
works, because when you use this function it finishes the response cicle and send a response. As explicit we can see in this code
So maybe, you can try to use the function write
to populate a response as you want, and after finish you can send the response explicit calling function end()
.
As an example:
//not tested code
router.options('/', (req, res, next) => {
res
.status(200)
.setHeader('Access-Control-Allow-Methods', allowFor('/')) // Without this line works fine.
.setHeader('Content-Type', 'application/json')
.write({
schema: schemafor('/')
})
//write more stuff, case needed, then finish response with end()...
res.end();
});
from express.
router.options('/', (req, res, next) => {
// Set the status code and headers
res
.status(200) // Set status code to 200 OK
.setHeader('Access-Control-Allow-Methods', allowFor('/')) // Set allowed methods header
.setHeader('Content-Type', 'application/json'); // Set content type header to JSON
// Manually construct the JSON response
res.write(JSON.stringify({
schema: schemafor('/') // Populate JSON response with schema data
}));
// End the response
res.end(); // Complete response
});
from express.
Related Issues (20)
- WebAssembly Out of memory Error for any server HOT 2
- return res.redirect('back'); returns to '/' instead of the previous page HOT 2
- Need a clarification on router.param() usage. HOT 7
- [Question] Should Express.js v5.x drop support to older versions of Node? HOT 3
- .get() attempting to grab from home dir (Linux) HOT 2
- Request triager role for Ivaylo-Iv HOT 1
- Request triager role for etroynov HOT 2
- clean code for switch condition HOT 2
- Response location broken for unicode domains in latest release HOT 1
- help typing Request query with object HOT 1
- Using colon as a character instead of path parameter (express 5) HOT 1
- Support HTTP `QUERY` method HOT 3
- Nominating @carpasse to the triage team HOT 7
- [v5] Lock down valid status code ranges to 1xx through 5xx HOT 10
- Error `cause` is not displayed HOT 5
- Cross-Origin-Opener-Policy HOT 1
- [v4] Deprecate `res.clearCookie` taking `maxAge` and `expires` parameters
- Attaching user-id header to axios interceptor in middleware (is it safe) HOT 1
- EDIT: False positive - HIGH vulnerability in dependency used, Cookie 0.6.0 HOT 2
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 express.