Plugin using Vapor - I come as far as OPTIONS

I am trying to implement a sample plugin and I come as far as being able to install it in Chrome. Safari refuses to send requisitions to http://localhost:8080.

I tried with or without CORS, all I ever get from ChatGPT is

OPTIONS /notes

to which I respond with:

Response Status: 200

Response Headers: [(“content-length”, “0”), (“access-control-allow-origin”, “https://chat.openai.com”), (“access-control-allow-headers”, “accept, authorization, content-type, origin, x-requested-with”), (“access-control-allow-methods”, “GET, POST, PUT, OPTIONS, DELETE, PATCH”), (“access-control-max-age”, “600”), (“vary”, “origin”)]

but then ChatGPT says something is wrong with my service… what? “Error making localhost plugin HTTP call: TypeError: Failed to fetch”

What am I missing? What’s the proper answer to OPTIONS /notes? Do I need to allow more headers?

cheers
Oliver

Hi Oliver,

Perhaps you could loosen your CORS options temporarily to help diagnose the issue. I would suggest setting access-control-allow-origin: * along with all the other CORS headers, and if that works, try limiting them one by one to the expected values and see if you can find what’s missing or incorrect that way? Just a thought…

-Ray

Makes no difference what I put there:

 **2023-06-29T00:03:57+0200 notice codes.vapor.application : [Vapor] Server starting on http://127.0.0.1:8080**

**2023-06-29T00:04:02+0200 info codes.vapor.application : request-id=52428872-3F29-48EB-BCFF-3BD71AB11DC6 [Vapor] OPTIONS /notes**

**[("Host", "localhost:8080"), ("Connection", "keep-alive"), ("Accept", "*/*"), ("Access-Control-Request-Method", "GET"), ("Access-Control-Request-Headers", "content-type,openai-conversation-id,openai-ephemeral-user-id"), ("Access-Control-Request-Private-Network", "true"), ("Origin", "https://chat.openai.com"), ("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"), ("Sec-Fetch-Mode", "cors"), ("Sec-Fetch-Site", "cross-site"), ("Sec-Fetch-Dest", "empty"), ("Accept-Encoding", "gzip, deflate, br"), ("Accept-Language", "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7,sk;q=0.6")]**

**Response Status: 200**

**Response Headers: [("content-length", "0"), ("access-control-allow-origin", "*"), ("access-control-allow-headers", "accept, authorization, content-type, origin, x-requested-with, user-agent, access-control-allow-origin, accept-language, server, host"), ("access-control-allow-methods", "GET, POST, PUT, OPTIONS, DELETE, PATCH"), ("access-control-max-age", "600"), ("access-control-allow-credentials", "true")]**

I believe this may be related to : Urgent Help Needed: Unable to Use Plugin on ChatGPT - #9 by raphael.j.segal

I got it working, I found I needed a couple of additional headers in CORS:

let config = CORSMiddleware.Configuration(
   allowedOrigin: CORSMiddleware.AllowOriginSetting.custom("https://chat.openai.com"),
   allowedMethods: [Vapor.HTTPMethod.GET, Vapor.HTTPMethod.OPTIONS, Vapor.HTTPMethod.POST, Vapor.HTTPMethod.PUT],
   allowedHeaders: ["content-type", "openai-conversation-id", "openai-ephemeral-user-id"],
   allowCredentials: false,
   cacheExpiration: 0
)

this also disables caching. I didn’t see the pesky OPTIONS any more after that.

And then I also got it working in Safari by using a self-signed certificate for localhost.

1 Like

Awesome, thanks for sharing the fix, I originally thought it might have been down to the issue yesterday, clearly that’s not the case.

In NodeJS, I have added the perfect source code to resolve it. I would be honored if it can be of help to you.