Skip to content
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

fix: invalid URL error when using expo-server-sdk inside API routes #128

Merged
merged 1 commit into from
Feb 5, 2025

Conversation

Savinvadim1312
Copy link
Contributor

I am using expo-server-sdk in an Expo project inside the API Routes.

When calling expo.sendPushNotificationsAsync([message]); I get an error code: 'ERR_INVALID_URL', input: '/--/api/v2/push/send'

I investigated and the problem seems to come from process.env['EXPO_BASE_URL'] being empty string instead of undefined.

I understand that this might be related to my local setup, but I checked and I don't set the EXPO_BASE_URL env anywhere.

Not exactly sure, but maybe the issue comes from Expo Router API Routes and how env variables are treated there?

Anyway, the suggested fix solves the issue by using the default base url, when the environment var is missing or is empty string.

I am using expo-server-sdk in an Expo project inside the API Routes. 

When calling `expo.sendPushNotificationsAsync([message]);` I get an error `code: 'ERR_INVALID_URL',  input: '/--/api/v2/push/send'`

I investigated and the problem seems to come from `process.env['EXPO_BASE_URL']` being empty string instead of undefined. 

I understand that this might be related to my local setup, but I checked and I don't set the EXPO_BASE_URL env anywhere. 

Not exactly sure, but maybe the issue comes from Expo Router API Routes and how env variables are treated there?

Anyway, the suggested fix solves the issue by using the default base url, when the environment var is missing or is empty string.
@Savinvadim1312 Savinvadim1312 requested a review from a team as a code owner February 5, 2025 11:59
@Savinvadim1312 Savinvadim1312 requested review from vonovak and removed request for a team February 5, 2025 11:59
Copy link

codecov bot commented Feb 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (4abc85a) to head (6d56935).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #128   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines          168       168           
  Branches        33        33           
=========================================
  Hits           168       168           
Flag Coverage Δ
node_18 100.00% <100.00%> (ø)
node_20 100.00% <100.00%> (ø)
node_22 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vonovak vonovak merged commit 8d9b75f into expo:main Feb 5, 2025
5 checks passed
@vonovak vonovak changed the title Fix Invalid URL error when using expo-server-sdk inside API Routes fix: invalid URL error when using expo-server-sdk inside API routes Feb 5, 2025
@vonovak
Copy link
Contributor

vonovak commented Feb 5, 2025

Thank you, this looks reasonable!

@Savinvadim1312 Savinvadim1312 deleted the patch-1 branch February 5, 2025 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants