-
Notifications
You must be signed in to change notification settings - Fork 353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does nextjs + capacitor support API routes on IOS #4
Comments
EDIT: found a solution in another repository where this was done
so when you are in native mode you use the api origin for requests and when your in webapp mode you let nextjs figure out that part for you. Hope this helped! |
Hey @appdevland interesting post and thanks for providing more info! Where would you put your code snippet? |
I am currently away from my computer so i can't write a code example but
you use that snippet to parse the url of any fetch requests that you make
for example: `fetch('/your/route', /....)
becomes: `fetch(functionabove(/your/route, .....
Hope this helped!
…On Tue, Jan 5, 2021 at 4:47 AM Max Lynch ***@***.***> wrote:
Hey @appdevland <https://github.com/appdevland> interesting post and
thanks for providing more info! Where would you put your code snippet?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKVLSZ2675BWBL2DNWRYTXLSYJVR7ANCNFSM4VQTIQ2A>
.
|
@appdevland How do you get the And, what is the value of |
Hey @agallio! It's been quite a while and i can't remember exactly. What you want to do in a nutshell is if your in web mode don't add an api origin to the project but if your in native mode (can be detected with capacitor) prefix an api_origin to all your fetch requests so that when your on mobile Wish i could remember more but it's been such a while. |
@agallio
In the simplest form, he's doing the following: const res = fetch(Capacitor.isNative ? 'https://my-nextjs-app.com/api/hello' : '/api/hello') |
hey so i found a solution to that where server url is not that buggy at all and i have worked on three projects so far and the solution for me was to serve assets from server and put server url in capactor server config but before that i run and get the apk of the project inspect it to get native-bridge.js and if native put its script before any bundler worked in create react app and on create next app all my fetches are from / i wish native-bridge.js was not made in android code so every one could do it much easer and for every capacitor plugin i have to redo the process again. |
Updated the README to add @appdevland's tip, thanks all |
Basically what it says on the tin....
I wanted to find out but it seems like no one really knows. Hopefully some of the folk visiting this repo know. Cheers!
The text was updated successfully, but these errors were encountered: