Making a JSON API request from meteor server - json

I have a Meteor application which I am to get to make a JSON API request from another service on the server.
I tried using the JQuery package and $.getJSON but as the JQuery package doesn't have any effect on the server, I quickly found this doesn't work.
How can I get the server to make a JSON request?

As you say... it isn't available on the server. You could experiment with changing the jQuery package in the meteor folder though.
In /packages/jquery/package.js change:
Package.on_use(function (api) {
api.add_files('jquery.js', 'client');
});
To:
Package.on_use(function (api) {
api.add_files('jquery.js', ['client', 'server']);
});
and see if it works on the server side. You have to call the server with your local changed copy of meteor, for me I do this by using ../meteor/meteor, your path may vary.

Related

http get from assets not work in published app Angular 9

i worked with Angular +9 and i've a problem when read json file from assets folder.
i am using the http module and the call works fine when the application is run locally, but when i run ng-build and publish the application on a server, the call to the json file doesn't work indicating the following message:
ERROR Http failure response for assets/resources/fakeData.json: 0 Unknown Error
My code:
What could be the problem? Why can't I access the assets folder directly?
Your problem is that you are trying to access your file system with the HttpClient. You can't do that. You could of course make an API Endpoint that returns your json file, but you can't access it directly like that with the HttpClient module.
Here what I would do instead:
import * as myJson from '<path to fakeData.json>';
...
getData(): any {
return myJson;
}
If you are just trying to mess around with HttpClient module and need some json to play with, you use JSON Placeholder API:
this.http.get('https://jsonplaceholder.typicode.com/todos/1');
According to the below SOF Question, it looks like you can get your local json files to be hosted along with the angular dev server if you wanted to:
Load json from local file with http.get() in angular 2
I don't know which web server you are using, but it looks like your web server does not support hosting of JSON-files.
Apache: use the AddType directive - https://cets.seas.upenn.edu/answers/addtype.html
IIS: Add a MIME-type - https://learn.microsoft.com/en-us/iis/configuration/system.webserver/staticcontent/mimemap

Crate DB with Nginx Binding

I was wondering is there a way to bind Nginx web server with CrateDB Backend to receive JSON data over https and store them in the CrateDB.So basically CrateDB should run as an appserver with nginx binding. The longer route would be to use php or python code to do this, but if there is an easier option available to do this it would be great. If any of you have been able to do this please let me know.The direct HTTP binding via REST API is a no go as it does not support HTTPS at this point in time. let me know your thoughts!
putting nginx as proxy in front of crate (and write an application in lua) is straight forward: https://crate.io/a/readonly-crate-with-nginx-and-lua/

How does restangular talk to MySQL database

I am total JS newbie working on a project build in Grail 2.4.4, a web-app. It's a working app, build by a developer whom is not available anymore.
To get it to work locally I had to upgrade it to Grails 3.2.0. I got it almost working in Netbeans. But I got stuck at getting the data from the MySQL database.
The Chrome inspector says:
angular.min.js GET http://localhost:8080/<app>/currency/allCurrencies 404 ()
The controllers are written in Restangular which call the above URL.
What am I missing?
Firstly, Restangular is an Angular library which simplifies and standardizes making calls to a REST backend (which in your case is a Grails app). So, Restangular does not directly retrieve data from your a database, it invokes a web service which (in some cases) may retrieve data from a database.
In your case, Restangular is attempting to retrieve data from the endpoint http://localhost:8080/<app>/currency/allCurrencies but you are getting a 404 response, indicating that there is no endpoint mapped to this URL.
HTTP REST helps you connect to the API easily. Restangular can handle that by sending standard methods [Get, Post, Delete, Put] to the api like what you see.
This mean StudentController > Get()
localhost:2045/api/student
This mean StudentController > Get(Guid id)
localhost:2045/api/student/8ae37cfa-905b-4c71-ad03-bf416d93bdf8
This mean StudentController > POST(Guid id) ... if you send Post method to the API, it will detect it, this work also on put method
localhost:2045/api/student
use this module to get easily rest api.
Http-Rest-Service

Liferay: Issue when Using JSON WebService and https

I have created a Liferay Web Service and made it accessible via JSON.
I call successfully call and use the JSON WebService using this URL:
https://localhost:8080/api/jsonws/my-portlet-name/my-method/time-unit/HOUR/class-name/TEST
I have annotated my Web Services like this:
#com.liferay.portal.security.ac.AccessControlled(guestAccessEnabled = true, hostAllowedValidationEnabled = false)
When I am using this call locally (http) I have no problems.
As soon as I deploy it to our test server (https) I do get "Forbidden - no permissions to access this resource".
What can I do to access my JSON Web Service calls ?
Ok, honestly : I donĀ“t know if there is an answer for that ;)
I have used the Liferay.Service js call to do the same and it works.
So no more URL calling from jQuery ...

MarkLogic 7 REST API - Bad Request Error

I am building a webapp using AngularJS on top of a MarkLogic 7 XML database. I am using the REST API provided by MarkLogic to access the database. The code I'm using in my controller is as follows.
app.controller("mainController", function($scope, $http){
var addr = 'http://localhost:8011/v1/search?q=test&options=newtest';
$http({method:'GET', url: addr})
.success(function(data){
alert('Success');
console.log(data);
});
});
Now, when I open my view, a 'bad request' error is logged in the console.
OPTIONS http://localhost:8011/v1/search?q=test&options=newtest 400 (Bad Request)
angular.min.js:99
OPTIONS http://localhost:8011/v1/search?q=test&options=newtest No 'Access-Control-Allow-
Origin' header is present on the requested resource. Origin 'null' is therefore not
allowed access. angular.min.js:99
XMLHttpRequest cannot load http://localhost:8011/v1/search?q=test&options=newtest. No
'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null'
is therefore not allowed access. index.html:1
Are there any settings to be configured on the MarkLogic server to make the API accessible? Please help.
Thanks,
Krishna
Krishna, is your AngularJS code hosted by MarkLogic, or are you running it in node.js (via grunt, perhaps)? This looks like a cross-site scripting problem. Two solutions come to mind:
If you don't need a middle tier, MarkLogic can host the Angular code. Put it in the modules database of the app server on port 8011. Then the request is going to the same place the JS came from and the problem goes away.
If you want to keep a node layer, set up a proxy. Assuming you're using Grunt, you can see how I handled that in the Gruntfile.js of an app with the same stack.
Once you get past that error, you might consider moving the interaction with the MarkLogic REST API into a service. The Demo Cat application I linked to above has an early version of an MLRest AngularJS service; that might be a useful starting point.