Shared function generates CORS error
Hey! I just finished the Wasp tutorial. Now trying to play around extending the TODO app.
I implemented a simple function I want to use both in the front and backend, so I put it in the
shared/
dir. It works as expected when I use it in the frontend, but if I invoke it in the backend I get a CORS error.
Am I missing any config steps?10 Replies
but if I invoke it in the backend I get a CORS error.How do you invoke the function in the backend? Do you just import it and call it? To get a CORS error you ought to send a request client -> backend usually, are you also doing that? Are you using Actions & Queries or custom APIs? If possible, share your code here π
This is
shared/taskChecker.ts
And this is the server/actions.ts
The request that is causing the error is the query that gets the tasks
And you are running your app with
wasp start
and get the CORS error? Do you get any other errors in the terminal?
I suspect that server is not running due to some random error and thus causing CORS error on the client@miho could it be the import needs to be from
shared/taskChecker.js
?
or has that been fixed?That could be it π let's see the terminal output and confirm
Yes, changing the import to
shared/taskChecker.js
fixed that! Thank you and sorry for the newbie question πWohooo @OliverL, you just became a Waspeteer level 1!
no worries. this is an issue I run into a lot
refresh my memory @miho when do the imports need .js extension and when don't they? and won't we be fixing that in the future so that imports won't need the .js extension at all?
We will change in at some point yep π
Imports on the client don't need it, importing TYPES on server is also fine, all other imports on the server require the extension π
Nice clarification