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

403 Forbidden #34

Closed
frederiko-famobi opened this issue May 5, 2023 · 2 comments
Closed

403 Forbidden #34

frederiko-famobi opened this issue May 5, 2023 · 2 comments

Comments

@frederiko-famobi
Copy link

frederiko-famobi commented May 5, 2023

Hello, after following the example project, I managed to make the server work.

But now I am getting an error 403 Forbidden on the webview for Android.

image

My project logs (following the example project) are the following:

LOG Extracting web server assets...
LOG Server #20844. New state: "STARTING". Details: "".
LOG Server #20844. New state: "ACTIVE". Details: "".

I checked the origin state and the uri is http://localhost:34797.

I tried to add to the webview:

      originWhitelist={['*']}
          source={{
            uri: origin,
            headers: {
              'Access-Control-Allow-Origin': '*',
            },
          }}

I also changed the assets files/folder to chmod 777.

But no success.

I am currently using Expo and had to install the library react-native-fs so the project would work. Usually we use expo-file-system, not sure if this is related or not.

If I set the property in the server to nonLocal: true and try to open in the browser and the same error 403 appears.

How can I solve this problem?

@birdofpreyru
Copy link
Owner

Well, you remember, Expo isn't officially supported (#8, #19). I bet, with the regular Android build example app works fine with last release (I just double-checked it):
image

Anyway, what you shared so far sounds like the server per se works fine. Are you actually running the example app as is? Because, my first guess would be that you accessing http://localhost:34797 without having any index file in the folder served by the server (which is configured to be one of these, and in the example app it would be index.html), so it probably attempts to list all content of the served folder, it is denied by OS, and thus it responds with 403 error. Though, it presumably able to see the directory to be served exists, as otherwise it would respond with 404 or 500 error.

@frederiko-famobi
Copy link
Author

Hello @birdofpreyru, after your reply and analysing the example code, I noticed that in the Expo generated android files, it was missing the following config in android/app/build.gradle:

android {
 ... 
 
    sourceSets {
      main {
        assets.srcDirs = ['../../assets']
      }
    }

After adding this, it worked fine. :) Now I see the same as you sent in your screenshot.
Thank you!!

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

No branches or pull requests

2 participants