Connecting to DreamFactory from a remote server

I have DreamFactory up an running and want to use it solely to house a database and handle api calls to that database from a webserver on another domain. I’ve set up CORS in DF with *, but am still getting the error that my domain “is not allowed by Access-Control-Allow-Origin”.

I’ve been googling and searching the forum, but have yet to find a solution. How can I make API calls from my site on another server?

Hello,

In when you login inside the Dreamfactory, in the menu have the option:
Config > CORS

Can add the endpoints available, normally this works.

Form Example:
> PATH: api/v2/user/*
> DESCRIPTION: API Users
> ORIGINS: *
> HEADERS: *
> EXPOSED HEADERS:
> MAX AGE: 0
> METHODS: PUT, GET, POST, PATCH
> [checked] ENABLED

Save and then test your call’s.

Best regards,
LB

It seems it is formulating the calls that I’m having trouble with. I’ve never worked with CORS before and have been googling around and trying several different things and still getting the same cross-origin answers. I’ve been trying:

$.ajax({
type: "POST",
url: "http://208.113.129.45"
}).done(function (data) {
console.log(data);
});

Is anyone here able to connect to my server at http://208.113.129.45 ?

Hello again,

When you made the call need to provide HEADERS (except for user login).
Using the
url: "http://208.113.129.245"
you can get a html content from your website, not access the API!

Can use the app “Postman” to make request, is not the same as a Javascript, because no CORS problems, but can validate if the API is correct or have issues in DF.

But can try in JS something like this to make a User Login:

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "http://www.yourdomain.com/api/v2/user/session",
  "method": "POST",
  "headers": {
    "Content-Type": "application/json",
    "Cache-Control": "no-cache"
  },
  "processData": false,
  "data": "{  \"email\":\"email@domain.com\",  \"password\":\"funnypassword\" }"
}

$.ajax(settings).done(function (response) {
  console.log(response);
});

Good luck!
LB

I’m still having not luck connecting from another server. I tried this on the same server and it returned a session token.

var settings = {

“async”: true,
“crossDomain”: true,
“url”: “http://208.113.129.45/api/v2/user/session”,
“method”: “POST”,
“headers”: {
“Content-Type”: “application/json”,
“Cache-Control”: “no-cache”
},
“processData”: false,
“data”: “{ “email”:"guest@gmail.com”, “password”:“guestPass” }"
}

$.ajax(settings).done(function (response) {
console.log(response);
});

From another server, I still get the cross-origin errors. Any other suggestions?

FINALLY got it. Cross-origin wasn’t enabled on apache.

Followed this guide: https://enable-cors.org/server_apache.html

1 Like