getting can't validate error (13) for mlab for heroku - mongodb

I'm trying to connect to a mongoDB instance hosted by mlab from heroku but It just keeps responding with:
`validate!': not authorized for query on .lotto_results (13)'
Which doesn't make sense as the user account has dbOwner role which means it should be able to read and write.
I found somthing about how heroku's nature (how it restarts) can cause problems but It didn't seem to explain how to fix it ( I would like to give a link to this but I can't seem to find the web page, it was a google thread I think).
I'm using the mongoid gem, with sinatra and grape and sprockets for assets (if that helps).
Not sure what else to mention, if there's anything else just ask and I'll try to answer it.

In the end I solved the problem by changing my config to:
development:
clients:
default:
uri: <%= ENV['MONGOLAB_URI'] %>
which used the pre-generated uri and it suddenly started working, well kind of, I'm still having issues but it's not an authentication issue at least.

Related

Netlify deploy can't connect to Heroku backend

I've built a wee program that works fine when I run it locally. I've deployed the backend to Heroku, and I can access that either by going straight to the URL (http://gymbud-tracker.herokuapp.com/users) or when running the frontend locally. So far so good.
However, when I run npm run-script build and deploy it to Netlify, something goes wrong, and any attempt to access the server gives me the following error in the console:
auth.js:37 Error: Network Error
at e.exports (createError.js:16)
at XMLHttpRequest.p.onerror (xhr.js:99)
The action that is pushing that error is the following, if it is relevant:
export const signin = (formData, history) => async (dispatch) => {
try {
const { data } = await api.signIn(formData);
dispatch({ type: AUTH, data });
history.push("../signedin");
} catch (error) {
console.log(error);
}
};
I've been tearing my hair out trying to work out what is changing when I build and deploy, but cannot work it out.
As I say, if I run the front end locally then it access the Heroku backend no problem - no errors, and working exactly as I'd expect. The API call is correct, I believe: const API = axios.create({baseURL: 'http://gymbud-tracker.herokuapp.com/' });
I wondered if it was an issue with network access to the MongoDB database that Heroku is linked to, but it's open to "0.0.0.0/0" (I've not taken any security precautions yet, don't kill me!). The MDB database is actually in the same collection as other projects I've used, that haven't had this problem at all.
Any ideas what I need to do?
The front end is live here: https://gym-bud.netlify.app/
And the whole thing is deployed to GitHub here: https://github.com/gordonmaloney/gymbud
Your issue is CORS (Cross-Origin Resource Sharing). When I visit your site and inspect the page, I see the following error in the JavaScript console which is how I know this:
This error essentially means that your public-facing application (running live on Netlify) is trying to make an HTTP request from your JavaScript front-end to your Heroku backend deployed on a different domain.
CORS dictates which requests from a frontend application are ALLOWED to make a request to your backend API.
What you need to do to fix this is to modify your Heroku application and have it return the appropriate Access-Control-Allow-Origin header. This article on MDN explains the header and how you can use it.
Here's a simple example of the header you could set on your Heroku backend to allow this to work:
Access-Control-Allow-Origin: *
Please be sure to read the MDN documentation, however, as this example will allow any front-end application to make requests to your Heroku backend when in reality, you'll likely want to restrict it to just the front-end domains you build.
God I feel so daft, but at least I've worked it out.
I looked at the console on a different browser (Edge), and it said it was blocking it because it was mixed origin, and I realised I had just missed out the s in the https on my API call, so it wasn't actually a cors issue (I don't think?), but just a typo on my part!
So I changed:
const API = axios.create({baseURL: 'http://gymbud-tracker.herokuapp.com' });
To this:
const API = axios.create({baseURL: 'https://gymbud-tracker.herokuapp.com' });
And now it is working perfectly ☺️
Thanks for your help! Even if it wasn't the issue here, I've definitely learned a lot more about cors on the way, so that's good

Netlify returning 404 when connecting to Atlas MongoDB

I'm trying to make a Netlify app that posts data to an Atlas MongoDB, and while I can post to the DB when I run my page from localhost, Netlify is returning a 404 whenever I attempt to post data to the DB. I know it is not an issue with Atlas's whitelisted IP addresses because I have whitelisted all IP addresses for the time being. I suspect that this has something to do with Netlify not properly reading or running the env.process that I'm using to store my Atlas information, although I am not completely certain that is the cause. When I run it locally, I have my config set up to simply use the Atlas information directly rather than relying on a .env file. I'm using mongoose to connect to the DB, and the connection portion of my code is the following in my production build:
mongoose.connect(process.env.MONGODB_URI || "mongodb://localhost/dbname");
This has not been working, but on the working copy that I run from localhost, I use:
const uri = `mongodb://atlasDB:<PASSWORDHERE>#atlasDB-shard-00-00-ot2tv.mongodb.net:27017,atlasDB-shard-00-01-ot2tv.mongodb.net:27017,atlasDB-shard-00-02-ot2tv.mongodb.net:27017/test?ssl=true&replicaSet=atlasDB-shard-0&authSource=admin&retryWrites=true`;
mongoose.connect(uri);
I have configured Netlify to have a MONGODB_URI build environmental variable of mongodb://atlasDB:<PASSWORDHERE>#atlasDB-shard-00-00-ot2tv.mongodb.net:27017,atlasDB-shard-00-01-ot2tv.mongodb.net:27017,atlasDB-shard-00-02-ot2tv.mongodb.net:27017/test?ssl=true&replicaSet=atlasDB-shard-0&authSource=admin&retryWrites=true
I have replaced PASSWORDHERE with the actual password in both instances, but the Netlify build environmental variable does not feature string quotations around the value when viewed in the entry field on the Netlify website. I tried putting them in, but it seemed to make no difference, but I may have simply not waiting long enough for the change to take effect.
Aside from Mongoose, I am not running any other dependencies that should have any effect on this problem. The project deadline is in a couple days, so any help with this would be greatly appreciated.

SIP extention created by FusionPBX can not login into softphone

I have a FreeSWITCH v1.6.13 on my Debian 8( From git) and it is OK.
After that i installed the last FusionPBX to manage my PBX telephony FS.
But it gives me error : 403 You must define a domain called x.x.x.x in your directory...
Both i installed by FusionPBX guid in their web site.
FreeSWITCH and FusionPBX.
Im going crazy cause about 4 days i Am working and not a good result yet.
I know Fusion store data in DB and i give him a Pgsql user name and password.( not the default one it suggest after ./install command) and also FS with --enable-core-pgsql-supprt in ./configureaiton with -C.
And i searched a lot, and all says as this link.
But when i go to sip status from FusionPBX, it says that my ip is correct, and also i did what they say but no success.
Just one time it worked! and i did not why it work.
And after it does not work and again says 403 you must ....
And after that i create an extention, i go to FS terminal and type user_exist 101 (user i created in fusionpbx)it return me false.
Can it be DB issue?
I do not know why just one time it worked and after i after that again gave me 403 error.
Cause i did changed a lot i could not understand what was the cause to work it.
Is it a bug?
What exactly i am doing wrong??
Really any help will appreciate.
EDIT 1 :
My softphone is android zoiper for test the created extention in fusion.
Make sure you are using the "Extension" number as the username in zoiper. Also go to the extension's settings page to see the current password for that extension. I have used Zoiper on my android phone with FusionPBX. So I know it will work.
Zoiper account settings will be:
Account Name: Any name.
Hostname: ip/hostname of FusionPBX
Username: extension number
Password: extension password.
One thing that confused me a lot when I first tried fusionpbx is the "Users" vs "Extensions". From what I can tell "Users" are only for logging into the web UI of FusionPBX, for things like checking voicemail and managing other features. The "Users" are not SIP users.

FactoryGirl.create issues "LocalJumpError: no block given (yield)" with Rails 5

I'm in the process of upgrading my app to Rails 5
When running the tests with rails 5 enabled I started to get "LocalJumpError: no block given (yield)" on several object creation sentences like this one:
let!(:entity) { create(:entity) }
This started to happen after I upgraded to Rails 5.0.0
I tried using build instead of create on that line and the error doesn't show up in that case.
Has anyone got a similar issue?
My Entity factory is this one:
FactoryGirl.define do
factory :entity do
entity_type 'A'
account { create(:account) }
ilk []
after(:build) do |entity|
entity.names << build(:name)
entity.addresses << build(:address)
end
trait :incomplete do
incomplete true
end
end
My Gemfile looks like this: https://jpst.it/Lb6N
EDIT
I found out the issue is not with FactoryGirl but with Mongoid gem. I opened a ticket on JIRA for that project. Here's the link but you'll need to have an account with access to Mongoid project at JIRA: https://jira.mongodb.org/browse/MONGOID-4302
The details of this ticket are that by running rspec -b to see the trace, I identified the issue on this line on the mongoid gem:
https://github.com/mongodb/mongoid/blob/master/lib/mongoid/clients/options.rb#L25
The issue disappears if I replace that line (yield self) with just:
self
I'm not sure however if this is a feasible fix, so I opened the ticket mentioned before to get mongoid's feedback and see what can be done.
I'll update again when I get any feedback.
After a lot of debugging I found the source of the issue on a local fork of the mongoid_token gem, which was causing this weird problem. Mongoid and FactoryGirl gems are not related to this issue, neither the original mongoid-token gem.

Setting moodle online

Good day everyone, I have been trying to put my moodle online so pcs from internet can access it, but until now, no luck at all. (Im using moodle 2.3.2 on Windows Server 2008 and IIS 7).
I tried to configure the moodle file config.php, setting the directive $CFG -> wwwroot = "my-public-ip/moodle". Then, when I access to moodel from the server, I can access it by "http://my-public-ip/moodle", when I try to access via localhost, it sends an error which it is OK.
But the funny part comes when I try to access the server from an outside pc. When I type "http://my-public-ip/moodle" it simply cant "see" the configuration I made to the config.php file (it says: This server cna only be accessed via localhost/moodle) it looks like the outside pcs are either ignoring it, or searching for another configuration file. I dont know what the hell is happening, this is very odd.
Any ideas?? tnx!!!
Change the following file:
lib-->setuplib.php
Redirect ($CFG->wwwroot, get_string('wwwrootmismatch', 'error', $CFG->wwwroot), 3);
for
Redirect ($CFG->wwwroot, get_string('wwwrootmismatch', 'error', $CFG->wwwroot), 0);
I realise this is an old question, but it's also worth pointing out you may need to also run the database search and replace script, at:
http://my-public-ip/moodle/admin/tool/replace/index.php
as referenced in Method 2 here.
This is required if you change the name of the site once you have installed it. If you were already using Moodle under "localhost", then there will be a number of references to the old localhost address stored in the database that need to be updated to the new IP-based address.
It might be because the http:// part is missing?
$CFG->wwwroot = "my-public-ip/moodle"
should be
$CFG->wwwroot = "http://my-public-ip/moodle"