W
Waspβ€’2y ago
jv

CORS question

is it possible to allow api to accessed outside the client url?
23 Replies
miho
mihoβ€’2y ago
1️⃣ If you are trying to communicate from a client hosted on a different client URL than the one configured with WASP_WEB_CLIENT_URL, here's the situation: There is a security feature in browsers called CORS (Cross-origin resource sharing) which controls from which URLs can you access certain servers. In the future (very soon) we plan to offer CORS customisation, so you can send requests to the backend from clients living on a different URL that the WASP_WEB_CLIENT_URL -> so, not possible at the moment 2️⃣ If you are trying to send requests from a mobile app for example, then you can, since the requests are not sent from a browser, so no CORS issues. But we are not offering first-party support for that use of Wasp just yet! You would need to figure out the API endpoints by inspecting the requests in the console. That might change in the future as well πŸ™‚ -> possible, but you would need to figure out the API
jv
jvOPβ€’2y ago
thanks
shayne
shayneβ€’2y ago
what type of app are you looking to build @jv? maybe we can help more with various options if you can provide a bit more detail on the use case. thanks!
jv
jvOPβ€’2y ago
i was just thinking of letting other client url access the server api, I am having an app that is synchronous, and its waiting for a callback, that is from another service that is running.
shayne
shayneβ€’2y ago
ah ok cool, as @miho mentioned if it is another backend service (non-browser) then you should just be able to call it directly since it should not check/care about CORS related stuff. we currently have a notion of Operations (Actions and Queries). those are mainly Wasp-related and we do some extra nice stuff there for users like handling data transfer between client and server, etc. they don't have "pretty URLs" or anything and aren't the main mechanism to use for exposing a public API really. coming this week we are launching an api keyword that will allow you to specify a verb and path pair (like GET /foo/bar) and associate to a JS/TS function (similar look and feel to Operations). this may help your use case too, so keep your eyes peeled and let us know if you have any questions as you start your implementation. πŸ‘
jv
jvOPβ€’2y ago
thanks shayne
Manan
Mananβ€’15mo ago
I'm seeing this CORS error as well because the backend and frontend are living on separate URLs. Any way around it?
No description
Manan
Mananβ€’15mo ago
This is happening while trying to login.
miho
mihoβ€’15mo ago
If you check the docs for deploying to Railway, we mention that you need to set the WASP_WEB_CLIENT_URL env variable to your client URL https://wasp-lang.dev/docs/advanced/deployment/manually#deploying-the-server
Deploying Manually | Wasp
We'll cover how to deploy your Wasp app manually to a variety of providers:
Manan
Mananβ€’15mo ago
Already added. Still getting this.
Manan
Mananβ€’15mo ago
No description
miho
mihoβ€’15mo ago
Hm, super weird, I'm getting the same issue with your app. Did you try setting the env variable with the / at the end? It shouldn't make a different, but let's see if it does
Manan
Mananβ€’15mo ago
I'll try
miho
mihoβ€’15mo ago
This is an app I have deployed, basically the same setup as you have
No description
Manan
Mananβ€’15mo ago
/ is already there
miho
mihoβ€’15mo ago
Sorry, I meant to say without πŸ˜„
Manan
Mananβ€’15mo ago
Same result The stripe payment won't work. And I'm afraid my project will get disqualified because of this. Everything works fine If I run the project locally.
miho
mihoβ€’15mo ago
We want to figure this out πŸ˜„ can you share your repo with me in the DMs so I can try to debug it? πŸ™‚
Manan
Mananβ€’15mo ago
Sure.
martinsos
martinsosβ€’14mo ago
@miho you managed to fix this in the latest release, right?
miho
mihoβ€’14mo ago
Yes sir, @Manan is aware of the change as well πŸ™‚
Manan
Mananβ€’14mo ago
Yes. I confirm this has been resolved and I was really happy with the quick response. πŸ₯³
martinsos
martinsosβ€’14mo ago
Awesome!
Want results from more Discord servers?
Add your server