Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.

Cors policy error running poc-ipfs locally #6

Closed
Deca opened this issue May 5, 2020 · 11 comments
Closed

Cors policy error running poc-ipfs locally #6

Deca opened this issue May 5, 2020 · 11 comments

Comments

@Deca
Copy link

Deca commented May 5, 2020

I'm trying to run the poc on my local machine, followed the doc for the client and the api,
As I try to upload a file I get this error:
"Access to XMLHttpRequest at 'http://localhost:4000/ipfs' from origin 'http://localhost:3000' has been blocked by CORS policy:"

Now I'm aware about cross domain ajax requests and understand the underlying security issue.
But right now both scripts are running locally, so they should be able to communicate...or I'm missing something?

my config files for api and client are the following:

{ "node": { "provider": "https://nodes.thetangle.org:443", "depth": 3, "mwm": 9 }, "ipfs": { "provider": "cloudflare-ipfs.com", "token": "MYIPFSNODE_TOKEN" }, "dynamoDbConnection": { "region": "AWS-REGION", "accessKeyId": "AWS-ACCESS-KEY-ID", "secretAccessKey": "AWS-SECRET-ACCESS-KEY", "dbTablePrefix": "DATABASE-TABLE-PREFIX" }, "allowedDomains": [ "https://ipfs.iota.works", "https://ipfs.iota.org", "cloudflare-ipfs.com" ] }

{ "apiEndpoint": "http://localhost:4000/", "ipfsGateway": "https://ipfs.io/ipfs/:hash", "tangleExplorer": { "transactions": "https://utils.iota.org/transaction/:transactionHash", "bundles": "https://utils.iota.org/bundle/:bundleHash" }, "googleAnalyticsId": "" }

@obany
Copy link
Contributor

obany commented May 6, 2020

The allowedDomains in the api config should just list http://localhost:3000 not "https://ipfs.iota.works", "https://ipfs.iota.org", "cloudflare-ipfs.com"

@Deca
Copy link
Author

Deca commented May 6, 2020

Thanks, it works now but had to edit the .\dist\data\config.local.json and not the one in .\src\data\ as stated in the doc

I'm now facing another error, after the upload submission I get a json response with {"success":false,"message":"TypeError: Cannot read property '1' of null"} no further detail in the logs
This could be something related to the online ipfs gateway I'm trying to connect? Should I try to switch to a local one?

@obany
Copy link
Contributor

obany commented May 6, 2020

You edit the one in src and then do a build, it gets copied into dist as part of the build process.

I added an extra catch for that error fce4c4b, it is caused by the format of the IPFS provider being incorrect, it should be in the form https://ipfs.mydomain.com:443/api/v0/

@Deca
Copy link
Author

Deca commented May 10, 2020

Have some time now for try to run this poc...thanks for the clarification about the build step, I got over the CORS issue.
Still wondering how to setup the conf files, now I get a NetworkingError: getaddrinfo ENOTFOUND dynamodb.aws-region.amazonaws.com

I thought that the dynamoDbConnection parameters were something optional but that not the case...
I've limited knowledge of .ts and having hard time to read the code, if I'm correct I see that tx's are store and retrievied on the AWS dynamodb...what's the purpose? To have permanent retention of the ipfs hashes when the snapshot on the iota node occurs?

This is something would be nice to have explained in the doc imho
Also I think it should be an optional configuration for the proof of concept itself and reduce the overhead of having it up and running

@obany
Copy link
Contributor

obany commented May 14, 2020

Yes as you inferred the dynamodb acts as a caching proxy for the transactions, so that if removed during a snapshot everything still works. The ideal implementation is to have a permanode and then the dynamodb part is not necessary for storing transaction data.

The dynamodb is also used to save some state of the services.

@Unimmms
Copy link

Unimmms commented May 14, 2020

Can you answer why I have a CORS problem when I want to retrieve a file.like this, "Access to XMLHttpRequest at 'http://localhost:8080' from origin 'http://localhost:3000' has been blocked by CORS policy". My ipfsGateway is 'http://localhost:8080/ipfs/:hash'?How can I solve this?

@obany
Copy link
Contributor

obany commented May 15, 2020

There must be some kind of CORS config required for IPFS, see a similar issue for ipfs ipfs/kubo#2239

@Unimmms
Copy link

Unimmms commented May 15, 2020

Thanks, I forgot to set the ipfsGateway to allow cross domain.

@Deca
Copy link
Author

Deca commented May 15, 2020

Thanks for clarifying that out @obany, I'll keep in mind to give a look to permanodes development and in the meantime try to run the poc with the actual setup

@Deca
Copy link
Author

Deca commented Jun 4, 2020

What is the correct aws endpoit for the 'region' parameter in the dynamodbconnection setup?
I've tried:
dynamodb.eu-central-1.amazonaws.com
or simply:
eu-central-1

But i get this error:
NetworkingError: getaddrinfo ENOTFOUND dynamodb.aws-region.amazonaws.com

@obany
Copy link
Contributor

obany commented Jun 4, 2020

its just the plain region part eu-central-1

@obany obany closed this as completed Nov 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants