Skip to main content
Participant
Jun 20, 2022 2:19 AM UTC
Answered

CORS Issue with Coldfusion REST API local

Hey there,

 

I'm playing around with CF locally with a Reac Front End, for speed of testing I'm using the built in webserver to see whether it's work keeping legacy CF components for a REST API.

 

I can get the GET and POST methods to work but am getting a CORS issue with DELETE.

 

I've tried including the following inside my Rest service but still no luck.

 

<cfheader name="Access-Control-Allow-Origin" value="*" />
<cfheader name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE" />
<cfheader name="Access-Control-Allow-Headers" value="Content-Type" />
 
Any help would be much appreciated.
Cheers
    This topic is closed to new replies. Start a new post to keep the conversation going.
    DemiurgeCorrect answer
    Participant
    Jun 20, 2022 11:47 PM UTC

    Thanks guys for the reply.

     

    I managed to get it working by setting up Apache, and running the connector, creating and signing my own cert for MacOS and then adding in the correct headers inside my virtual directory.

     

    Bit of a stuff around by everything works as it should

     

    Cheers

    4 replies

    DemiurgeAuthorCorrect answer
    Participant
    Jun 20, 2022 11:47 PM UTC

    Thanks guys for the reply.

     

    I managed to get it working by setting up Apache, and running the connector, creating and signing my own cert for MacOS and then adding in the correct headers inside my virtual directory.

     

    Bit of a stuff around by everything works as it should

     

    Cheers

    Translate
    BKBK
    Community Expert
    Community Expert
    Jun 21, 2022 10:28 AM UTC

    Thanks for sharing that.

    Translate
    BKBK
    Community Expert
    Community Expert
    Jun 20, 2022 10:02 AM UTC

    In any case, you can simply use the OPTIONS request to ask the API whether it allows DELETE. Something like:

     

    <cfhttp url="https://reqres.in/api/users" method="options">
    	<cfhttpparam type="header" name="Access-Control-Request-Methods" value="DELETE" >
    </cfhttp>
    <cfdump var="#cfhttp#" >

     

    Translate
    BKBK
    Community Expert
    Community Expert
    Jun 20, 2022 8:32 AM UTC

    Could you please tell us what the issue is?

     

    What do you do? What do you get as a result? Please share the relevant code and error messages.

    Translate