Giter VIP home page Giter VIP logo

Comments (4)

wesleytodd avatar wesleytodd commented on May 21, 2024

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.

danizavtz avatar danizavtz commented on May 21, 2024

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.

Codexnever avatar Codexnever commented on May 21, 2024
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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.