Using Cloud Code with the Parse Server and Heroku - ios

I am trying to understand the new Parse Server and have deployed on Heroku. This went smoothly but what I am struggling with is figuring out how to write server side code (Cloud Code). I've read over the parse server example many times so I must be missing something but I'm very unclear if I should be using Express for something, or how I even begin to include my Cloud Code files. Any help is very much appreciated.
UPDATE:
I found the cloud folder I was just looking in the wrong place. I moved it and index.js to my apps folder on the desktop. I have changed the default code in main.js to my custom code. I have set up index.js with my apps information. The problem now is when I run the app and try to call the cloud code functions I get error invalid function.

If you have the parse server example running on heroku you are 90 percent there. Just open the cloud/main.js file and start adding your cloud code. There should be a hello cloud function there as an example.
To use your already created cloud code modules/files you can require them as you have done before on parse.com. The only difference is that the path should now be relative instead of absolute. For example require('cloud/cloudFunctions'); should be require('./cloudFunctions'); if you had a module called cloudFunctions.js in the cloud directory.
Cloud Code works similar to how it did on parse.com and you shouldn't have to think too much about expressjs for simple applications. That said, parse server is using expressjs so yes you are using it.
Parse server is simply a another node module similar to the other thousands available. If you do not have previous experience with nodejs, running parse server can seem complicated. Therefore I would recommend reading about the basics of nodejs before a full migration.

I'm using the Bitnami stack on a Google Compute Engine instance and I had a similar problem to yours. To solve it, just navigate to the folder where your server.js file is and create a folder called "cloud". Then create the main.js file inside the cloud folder with the following content:
Parse.Cloud.define('hello', function(req, res) {
res.success('Hi');
});
Now open the server.js file and find the line containing the path to the cloud code file. Change it to point to you main.js file like this:
This could be any arbitrary folder of your choosing.
Now just restart your parse server and call the cloud function:
String result = ParseCloud.callFunction("hello", new HashMap<>());
This is with the Java SDK but should not be much different. The variable result will equal "Hi" if you've used the function from above.

Related

How do I get a Replit secret key to work using Svelte?

I'm stuck on what seems like a simple task. I want to run a weather app I built in Svelte and run it on Replit. The app uses an API with a key, so I added my key to Secrets in Replit and gave it the name MY_API_KEY.
In the file that calls the API, I used the following:
const MY_API_KEY = process.env.MY_API_KEY;
Unfortunately, that doesn't work. My app doesn't load. When I change the variable in my file to include the key itself, the app runs fine, so I must not be calling up the environmental variable right. Does anyone know how this works in Svelte? I'd appreciate any help.
The base Svelte template on Replit uses Vite for building it's apps. This means you can do it the Vite way:
Call your environment variables something like VITE_ApiKey=123
And in your code use import.meta.env.VITE_ApiKey
Note that this only works for environment variables prefixed with VITE_

Parse Server Cloud Code Does Not Work

Hey guys I have a very confusing issue at hand, I want to state that I have looked through EVERY resource I could find including on here about getting custom cloud code functions to work.
I am hosting Parse Server on Heroku with my database on mLabs
I can successfully call the 'hello' cloud code function
I cannot successfully call any custom Function, even one that prints something to the console
Below is my current process that I have been using trying to get my cloud code functions to work
Open Main.js and Add Cloud code:
Parse.Cloud.define('testParagraph', function(req, res) {
console.log("received......... this is a console log for a test function that will print out a paragraph as a test");
res.success('Hi, this is the start of a new test function that will print out a paragraph');
});
Commit change to git
Push Change to git
Restart Heroku Server
Run App & Call cloud code from iOS app in Swift
Result:
Every Time I get error 141 Invalid Function, however I can call 'hello' successfully. Just not a custom function.
Edit 2: I have discovered that I am unable to update any cloud functions. Meaning that while I can successfully call the "hello" function if I make a change to said function, re-upload to git, restart Heroku the change is not implemented. This leads me to believe that there must be something wrong with either the link to my main.js or it is being uploaded somewhere else and isnt calling the correct main.js... Any insight would be helpful
I solved this issue, my git was behind HEAD and therefore any changes I made did not become active on my Heroku Server, I merged my branches and this solved my problem of not being able to run custom functions. Now I am able to run custom functions, but I still get error 141 when try to query my database, due to the new problem I am marking this as solved and asking a new question.

local autocomplete using jQuery-Autocomplete and mockjax

https://github.com/devbridge/jQuery-Autocomplete
found this tutorial and was able to run it implement it on my app.my problem is, it wont run on local computer/app i think the problem is with mockjax is there way to make this tutorial run locally?or is there other way to make an autocomplete locally?this example is about autocomplete.
In the config lookup is for local data that doesn't rely on external requests. This would rely on loading in the data through JS on the client.
If you want to run it locally why not boot up a simple http server with python and make a get request to a local file?
See here line 133: https://github.com/michaelBenin/Airport-Distance-Calculator/blob/master/script.js

Using Celery with Pylons

I am trying to set up celery and pylons and can't seem to get it working. I downloaded pylons-celery, but how do I point my Pylons environment to where the celeryconfig.py is? I placed the config file in my pylons-app\celery folder. I read this post, but it doesn't mention how to pair celery with pylons.. Any pointers are appreciated - thanks!
The tightest integration with pylons is to build a custom loader into paste commands. This is what celery-pylons does. Check out my fork of celery-pylons which should work with the latest celery and pylons 1.0.
To get the celeryd side working you need to add the correct options in your ini file and then call paster celeryd development.ini
For the webapp side you just need to import celerypylons in environment.py Then you will be able to import and use your tasks from anywhere in your project.
I'm not exactly sure what you're trying to achieve, but I'll explain how I just setup Pylons to work with celery and hopefully you can gain something from it.
My setup is fairly simple. I implemented a REST API with Pylons using a single controller called jobs. When a POST request is received, the controller action would submit a new task to celery, capture the new tasks's uuid, and respond to the original request with the uuid. I originally place my celeryconfig.py file in my controllers directory, but once I deployed the pylons app egg to the apache web server, the celeryconfig.py was no longer automatically found.
To remedy this, I created a celery directory at the same level as the model and controllers directories, and I placed my celeryconfig.py file there, along with an empty init.py.
Here is a snippet of code from jobs controller where I connect to celery and submit a new task.
from celery import Celery
from my_pylons_app.celery import celeryconfig
celery_app = Celery()
celery_app.config_from_object(celeryconfig)
result = celery_app.send_task("process_job", [job_guid], connect_timeout=10)
I was able to get this working with both my internal paste web server and my public live apache2 web server.

Rabbitmq erlang client build failed due to file paths problems?

I have been able to build rabbitmq server on ubuntu linux. It came already prepackaged and on making, it is able to start as a service. When i got the client source, i failed to make because it appeared like it needed a folder called ./deps/rabbitmq-server. Analysing the code, i find that the author of the client was accessing the same header files as are found in the server, using include_lib("path to rabbit.hrl e.t.c") in his header file called "amqp_client.hrl". I then decided to add rabbitmq_server in the lib dir of erlang so as its paths are automatically added on start up of the vm. But still this didnot help. There is also another folder which the client references called "rabbit_common" for an include folder he assumes would contain all the .hrl files there. Please assist me in building both the client and server on my ubuntu server, for testing.
Also, if anyone has used RabbitMQ server for IMs, please provide some benchmarks and/or your findings on its throughput, speed and number of users. How can it be compared to ejabberd?. How can one create AJAX/Jquery/Javascript clients for Web functionality?
thanks
I hope you had made some progress as far as RabbitMQ and ejabberd are concerned.
Below is a link to an interesting discussion that might be of help.
http://old.nabble.com/AMPQ-vs-XMPP-and-RabbitMQ-vs-ejabberd-td17587109.html

Resources