HTTP-GET Request with Titanium.Network.createHTTPClient() to coutchdb? - json

Im trying to make a request to my database on Coutch db in Titanium Studio.
I have tried the code bellow, but I get error: Cant retriev data.
If I try with ex url http://www.appcelerator.com, I can get the data.
If I use coutch db url http://127.0.0.1:5984, I can not get any data + error.
Im wondering if I maybe should use another url?
var url = "http://www.appcelerator.com";
var client = Ti.Network.createHTTPClient({
onload : function(e) {
Ti.API.info("Received text: " + this.responseText);
alert('success' + this.responseText);
},
onerror : function(e) {
Ti.API.debug(e.error);
alert('error');
},
timeout : 5000
});
client.open("GET", url);
client.send();

Your CouchDB server is run on your local machine and you can access it through 127.0.0.1 or localhost.
When you are running your code in iOS Simulator you have to remember it's virtual environment with different IP. To make proper query from iOS Simulator to CouchDB you have to use your real IP which can be retrieved from ifconfig command
ifconfig | grep inet | grep -v inet6 | cut -d ' ' -f 2

if this 127.0.0.1 is your local address then you should use locallhost.
Example :
http://localhost

Related

Node.js GraphQL API Stops working as soon as I deploy it: "Error validating datasource `db`: the URL must start with the protocol `mysql://"

I build a GraphQL API with Apollo and Prisma ORM which is connected to my hosted MySQL Database (The Database has already content in it).
When I run it on my localhost everything works fine and I can query the Database with GraphQL statements.
As soon as I deploy my node.js project to DigitalOcean (auto deployed with GitHub) it stops working and I get the following error:
{
"errors": [
{
"message": "\nInvalid `prisma.content.findMany()` invocation in\n/workspace/src/schema.js:36:29\n\n 33 const resolvers = {\n 34 Query: {\n 35 memes: (parent, args) => {\n→ 36 return prisma.content.findMany(\n error: Error validating datasource `db`: the URL must start with the protocol `mysql://`.\n --> schema.prisma:7\n | \n 6 | provider = \"mysql\"\n 7 | url = env(\"DATABASE_URL\")\n | \n\nValidation Error Count: 1",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"memes"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"clientVersion": "3.6.0",
"stacktrace": [
"Error: ",
"Invalid `prisma.content.findMany()` invocation in",
"/workspace/src/schema.js:36:29",
"",
" 33 const resolvers = {",
" 34 Query: {",
" 35 memes: (parent, args) => {",
"→ 36 return prisma.content.findMany(",
" error: Error validating datasource `db`: the URL must start with the protocol `mysql://`.",
" --> schema.prisma:7",
" | ",
" 6 | provider = \"mysql\"",
" 7 | url = env(\"DATABASE_URL\")",
" | ",
"",
"Validation Error Count: 1",
" at cb (/workspace/node_modules/#prisma/client/runtime/index.js:38689:17)",
" at processTicksAndRejections (internal/process/task_queues.js:97:5)"
]
}
}
}
],
"data": null
}
Here is my schema.prisma file:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
...
The only thing that is different from the hosted project compared to the local project is that I put .env file and node_modules on the .gitignore file.
So it seems like the project is accessing the wrong DATABASE_URL, but how should the hosted project know the DATABASE_URL in my .env file when the .env file is on .gitignore?
Here is what I do:
Change the DATABASE_URL in my .env file to my local MySQL Database hosted on a docker container
Run npx prisma migrate dev --preview-feature to generate the migration files
Run git add .
Run git commit -m "New Commit"
Run DATABASE_URL=mysql://censored:censored#censored:3306/censored npx prisma migrate resolve --applied "my_migration_folder_name" --preview-feature which succeeds and tells me "Migration my_migration_folder_name marked as applied."
Run git push
I can see that the Migration is successfully created on my MySQL Database but as soon as I run the app and try to query the database it gives me that error.
The code has to be correct because it is working on my localhost even when querying the hosted MySQL Database.
I also double checked that the Model in the schema.prisma file is in sync with my hosted MySQL Database schema.
I'm running out of ideas on what I could try.
EDIT
I actually think it has something to do with the environment variables I set in the settings of my DigitalOcean application.
Before it was set to:
envs:
- key: DATABASE_URL
scope: RUN_AND_BUILD_TIME
value: ${db.DATABASE_URL}
Now I set it to:
envs:
- key: DATABASE_URL
scope: RUN_AND_BUILD_TIME
value: mysql://censored:cesnored#censored:3306/censored
I thought that this will fix the problem but now it tells me that the connection fails because of wrong database credentials even though it is the right link with the right credentials.
I fixed it by clicking "Force rebuild and deploy" on my digitalOcean app.

Running WinRM quickconfig for remote servers

I am writing a PowerShell script that reads in a list of hosts from a file. I have tried two separate methods, having issues with both.
First Method:
$WinRM = Invoke-Command -Computer $server -ScriptBlock { WinRM quickconfig }
This gives the following error message on some of the hosts:
WSManFault
+ CategoryInfo : NotSpecified: (WSManFault:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
+ PSComputerName : svclebetapool01.lehi.micron.com
Message = Access is denied.
Error number: -2147024891 0x80070005
Access is denied.
Second Method:
$WinRM = C:\PSTools\PsExec.exe \\$server -s winrm.cmd quickconfig -q
This sets $WinRM to the exit code (1 on successful execution). If I redirect the output with > or >>, then it displays the PsExec copyright. I am looking for the exact message that is created by the WinRM quickconfig command so that I know how to handle it in different situations.
if your intention is to enable PowerShell remoting, then you can
C:\PSTools\PsExec.exe \\$server PowerShell.exe -c "Enable-PSRemoting -Force"
or
wmic /node:$Server process call create "PowerShell.exe -c 'Enable-PSRemoting -Force'"

LoopBack does not read port property from config.json (or other config files)

So I want to run multiple LoopBacks listening different ports (makes dev easier). I can achieve this by using PORT=808x node ., but I would prefer a configured alternative.
When I tried to use the configs, I noticed strange behavior. Other configs, such as the restApiRoot matches whatever I write for it in the server/config.json, but the port is always 8080, unless I use env variables or such. I checked the documentation for all configuration files LoopBack reads, non of them has new value for port. Where does that port value come from? How can I force it to use the one in server/config.json or in similar official configuration files?
UPDATE: My server/server.js server/config.json and package.json files
When I start this with node . command, the port variable is 8080 instead of 8082 and when I wget, the response (404) comes from 8080 and 8082 gives no response, as there is no server serving that port.
package.json
{
"name": "external-server",
"version": "1.0.0",
"main": "server/server.js",
"scripts": {
"pretest": "jshint ."
},
"dependencies": {
"compression": "^1.0.3",
"cors": "^2.5.2",
"loopback": "^2.22.0",
"loopback-boot": "^2.6.5",
"loopback-component-explorer": "^2.1.0",
"loopback-connector-mysql": "^2.4.1",
"loopback-datasource-juggler": "^2.39.0",
"serve-favicon": "^2.0.1"
},
"devDependencies": {
"jshint": "^2.5.6"
}
}
server/server.js
var loopback = require('loopback');
var boot = require('loopback-boot');
var app = module.exports = loopback();
app.start = function() {
// start the web server
return app.listen(function() {
app.emit('started');
console.log(app.get('port'))
var baseUrl = app.get('url').replace(/\/$/, '');
console.log('Web server listening at: %s', baseUrl);
if (app.get('loopback-component-explorer')) {
var explorerPath = app.get('loopback-component-explorer').mountPath;
console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
}
});
};
// Bootstrap the application, configure models, datasources and middleware.
// Sub-apps like REST API are mounted via boot scripts.
boot(app, __dirname, function(err) {
if (err) throw err;
// start the server if `$ node server.js`
if (require.main === module)
app.start();
});
server/config.json
{
"restApiRoot": "/api",
"host": "0.0.0.0",
"port": 8082
}
Okay, it seems that when I run LoopBack with sudo, the configuration files are applied. Very confusing.
So the command node . will lead to wrong port and sudo node . will read the port from the server/config.json. It seems like other configuration parameters are read correctly, even without sudo, for some reason PORT is a special case. There is a realted answer, which shows that this is a NodeJS + Express issue, not a LoopBack issue.

mosquitto 1.4 - once running with ACL enabled, gets "Socket error on client <unknown>, disconnecting"

following instructions from Jeremy Gooch, see http://goochgooch.co.uk/2014/08/01/building-mosquitto-1-4/, i installed mosquitto over websockets on RPi. i can sub/pub messages to test site http://test.mosquitto.org/ws.html
from that point, i enabled user and topic access control in mosquitto.conf for more tests, but the strange point is that when i start mosquitto again, i see socket errors per second...
sudo /usr/local/sbin/mosquitto -v -c /etc/mosquitto/mosquitto.conf
1429857948: mosquitto version 1.4 (build date 2015-04-20 22:04:51+0800) starting
1429857948: Config loaded from /etc/mosquitto/mosquitto.conf.
1429857948: Opening ipv4 listen socket on port 1883.
1429857948: Opening ipv6 listen socket on port 1883.
1429857948: Warning: Address family not supported by protocol
1429857949: New connection from 127.0.0.1 on port 1883.
1429857949: Sending CONNACK to 127.0.0.1 (0, 5)
1429857949: Socket error on client <unknown>, disconnecting.
1429857950: New connection from 127.0.0.1 on port 1883.
1429857950: Sending CONNACK to 127.0.0.1 (0, 5)
...
i modify the config file to enable ACL only, comment out all others, the socket errors are still there. config file looks now:
sudo nano /etc/mosquitto/mosquitto.conf
autosave_interval 1800
persistence true
persistence_file m2.db
persistence_location /var/tmp/
connection_messages true
log_timestamp true
log_dest stderr
log_type error
log_type warning
log_type debug
allow_anonymous false
password_file /etc/mosquitto/mqtt.pw
acl_file /etc/mosquitto/mqtt.acl
port 1883
protocol mqtt
i even test to use the sample password_file and acl_file, but same error.
searched on google, also no result, could anyone help on this? thanks.
1429857949: Sending CONNACK to 127.0.0.1 (0, 5)
CONNACK return code of 5 means the connection was not authorised. If it
works with allow_anonymous=true, then it sounds like your client isn't
sending a username / or isn't sending a correct username&password.
It looks like you have a Paho Python client running.
I had the same problem my solution was that I wasn't closing the connection. Once I added client.Disconnect() it solved my problem.
Code:
public IEnumerator ooverhere()
{
MqttClient client;
client = new MqttClient(urlPath, port, false, MqttSslProtocols.None, null, null);
client.ProtocolVersion = MqttProtocolVersion.Version_3_1;
byte code = client.Connect(Guid.NewGuid().ToString(), user, pass);
if (code == 0)
{
Debug.Log("successful connection ...");
//client.MqttMsgPublishReceived += client_recievedMessage;
Debug.Log("your client id is: " + client.ClientId);
client.Subscribe(new string[] { "example" }, new byte[] { 0 });
client.Publish("Helpme", Encoding.UTF8.GetBytes("#" + 0));
yield return client;
client.Disconnect();
}
}

mysql package isn't loading in nodejs

Have the following code -
var http = require('http');
var mysql = require('mysql');
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Hello World\n");
});
// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);
// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8000/");
When I'm trying to run I'm getting the following error -
Error: Cannot find module 'mysql'
Though I have mysql module installed.
Here is something weird, I did installed it with npm install mysql but...
npm ls
returns
└── (empty)
Running
"npm prefix"
returns /home/user, while
npm config get prefix
returns
/home/user/.node
Something that makes it even weirder is the fact that that I have the mysql package both in ~/.node/lib/node_modules/mysql and in ~/.npm/mysql/2.3.2/package (Also, .npm contains more packages)
I'd appreciate any help