mLab database not accessible from heroku hosted MEAN app - node.js

I have hosted my MEAN app on heroku using mlab to provide the mongodb database I need.
In my app, I connect to the database using :
mongoose.connect(process.env.MONGODB_URI);
In my app, I declare my model :
mongoose.model('Course', CourseSchema);
If I understand correctly, mongoose will look for a collection named Courses.
I have imported a collection into mlab using :
mongoimport -h <XXX> -d <XXXXX> -c Courses -u <XXXX> -p <XXXX> --file <XXXXX> --jsonArray
It worked, message : imported 350 documents
And yet, my app doesn't show any data while it works locally.
What could be happenning ? I'm a total beginner and don't really know where to start :)
EDIT :
In my app, I have a get request on the database triggered by the route : /courses
Here is what I get in the logs regarding that get request :
2016-06-09T17:33:57.000199+00:00 app[web.1]: GET /courses 304 2.473 ms - -
2016-06-09T17:34:34.739488+00:00 heroku[router]: at=info method=GET path="/" host=c
mtproto.herokuapp.com request_id=dbdef76d-78b2-4d4c-b509-a18c6194cc18 fwd="87.91.22
.213" dyno=web.1 connect=0ms service=2ms status=304 bytes=147
2016-06-09T17:34:34.734195+00:00 app[web.1]: GET / 304 1.106 ms - -
I'm really confused, I just tried my app locally with my local database (on localhost) without any issue.
Then I ran it locally using my mongolab uri to connect to the database managed by mlab. The connection worked (response : 200) but had no data in my app. I then proceded to use curl http://localhost:3000/courses and got an empty array in response.
I dont think the problem comes from the code of my get request since it works when I connect to my localhost database. Code of my get request :
router.get('/courses', function(req, res, next) {
Course.find(function(err, courses){
if(err){ return next(err); }
res.json(courses);
}).select({ "name": 1, "_id": 1, 'code': 1, 'courseContentGrade': 1, 'courseTeachingGrade': 1, 'courseAverage': 1});
});
It also looks like I do connect succesfully to the mlab database since I get a 200 code response.I get a 304 if I use a post request though.
here is what the data in db looks like :
[{
"_id": {
"$oid": "5759ddbfe71976730e6df425"
},
"code": "XXXXXX ",
"name": "Negotiation",
"courseContentGrade": "3.0",
"courseTeachingGrade": "8.0",
"courseAverage": "5.5",
"reviews": [
{
"name": "Advanced Negotiation Workshop",
"professor": "Aenean sed",
"contentReview": "Lorem ipsum dolor sit amet, consectetur adipiscing",
"teachingReview": "In in ipsum odio. Nulla sodales nulla vel vulputate lobortis. Curabitur ut.",
"contentGrade": 3,
"teachingGrade": 8,
"average": "5,5",
"trimester": "T3",
"day": "Semaine bloquée",
"time": "Semaine bloquée",
"round": "1er tour / 1st round",
"bet": 21,
"year": "2014/2015",
"upvotes": 0,
"author": "Piranha"
}
]
},
{
"_id": {
"$oid": "5759ddbfe71976730e6df42a"
},
"code": "XXXXXXXX",
"name": "Germany",
"courseContentGrade": null,
"courseTeachingGrade": null,
"courseAverage": null,
"reviews": []
}]
Any other hint on what I should be checking ?

Problem solved !
Mongo doesn't like capital letters, I renamed my collection with only lower case letters and everything is now working perfectly.
No idea why it was working on my computer and not on heroku though...

While deploying your apps, it's a good practice to keep API keys and auth related variables out of codebase. This way your secrets are safe, even when codebase is shared. These secrets can be applied to the run time using process.env object which can store all such environmental variables.
For heroku based deployments you can set your environment variables by using following command:
heroku config:set GITHUB_USERNAME=vikramtiwari
More details: https://devcenter.heroku.com/articles/config-vars
Once these variables are set your program can make use of it during run time. In your case, your MEAN app is trying to find those values, but couldn't get them, hence no data being displayed. Check your logs (heroku logs) to confirm that app is not connected to MongoDB.

Related

Issue with Keycloak and nestjs

I have been trying to include Keycloak authentication with my NestJS app and this is driving me crazy. I keep getting an error
"WARN [Keycloak] Cannot validate access token: Error: Grant validation failed. Reason: failed to load public key to verify token. Reason: connect ECONNREFUSED ::1:8080"
My Keycloak.json file is:
{
"realm": "my-realm",
"auth-server-url": "http://localhost:8080/",
"ssl-required": "external",
"resource": "test",
"verify-token-audience": false,
"credentials": {
"secret": "my-secret"
},
"policy-enforcer": {}
}
This is being imported in Apps.module.ts as:
KeycloakConnectModule.register('./dist/keycloak.json', {
policyEnforcement: PolicyEnforcementMode.PERMISSIVE,
tokenValidation: TokenValidation.ONLINE,
}),
I am using Keycloak version 19.0.1 and nest-key cloak-connect v 1.9.0.
When I tried debugging. Grant-manager.js's public key is undefined. I checked with the well-known config and jwks-uri was defined as:
http://localhost:8080/realms/my-realm/protocol/openid-connect/certs
Any ideas on what might be wrong?

Alpha release 'Deployed' but unavailable

I have built a Google Action using Dialogflow and having trouble releasing an updated version to Alpha today.
The updated action works OK in Draft and I submitted it for Alpha deployment. The Actions console is showing the release as "Deployed". However, when I try to access the Alpha version I get an "isn't responding right now" response (from the simulator, Home device and Assistant smartphone app). The backend fulfilment service which is shared by Draft and Alpha is working OK.
I can see the following in the Debug console on the simulator:
{
"response": "MyAction Test isn't responding right now. Try again soon.",
"expectUserResponse": false,
"conversationToken": "EucBS2o5Uk...",
"audioResponse": "//NExAAP+H...",
"ssmlMarkList": [],
"debugInfo": {
"assistantToAgentDebug": {
"curlCommand": "curl -v 'https://api.api.ai/api/integrations/google?token=XXXXX&versionId=20' -H 'Content-Type: application/json;charset=UTF-8' -H 'Google-Actions-API-Version: 2' -H 'Authorization: XXXXX' -A Google-ActionsOnGoogle/1.0 -X POST -d '{\"user\":{\"accessToken\":\"eyXXXXX\",\"locale\":\"en-US\",\"lastSeen\":\"2019-09-12T09:58:03Z\",\"userStorage\":\"{\\\"data\\\":{\\\"welcomes\\\":53,\\\"intentCounts\\\":{\\\"BALANCE\\\":2}}}\",\"userVerificationStatus\":\"VERIFIED\"},\"conversation\":{\"conversationId\":\"ABXXXXXX\",\"type\":\"NEW\"},\"inputs\":[{\"intent\":\"actions.intent.MAIN\",\"rawInputs\":[{\"inputType\":\"KEYBOARD\",\"query\":\"Talk to MyAction Test\"}]}],\"surface\":{\"capabilities\":[{\"name\":\"actions.capability.AUDIO_OUTPUT\"},{\"name\":\"actions.capability.SCREEN_OUTPUT\"},{\"name\":\"actions.capability.ACCOUNT_LINKING\"},{\"name\":\"actions.capability.WEB_BROWSER\"},{\"name\":\"actions.capability.MEDIA_RESPONSE_AUDIO\"}]},\"availableSurfaces\":[{\"capabilities\":[{\"name\":\"actions.capability.WEB_BROWSER\"},{\"name\":\"actions.capability.SCREEN_OUTPUT\"},{\"name\":\"actions.capability.AUDIO_OUTPUT\"}]}]}'",
"assistantToAgentJson": "{\"user\":{\"accessToken\":\"eyXXXXX\",\"locale\":\"en-US\",\"lastSeen\":\"2019-09-12T09:58:03Z\",\"userStorage\":\"{\\\"data\\\":{\\\"welcomes\\\":53,\\\"intentCounts\\\":{\\\"BALANCE\\\":2}}}\",\"userVerificationStatus\":\"VERIFIED\"},\"conversation\":{\"conversationId\":\"ABXXXXX\",\"type\":\"NEW\"},\"inputs\":[{\"intent\":\"actions.intent.MAIN\",\"rawInputs\":[{\"inputType\":\"KEYBOARD\",\"query\":\"Talk to MyAction Test\"}]}],\"surface\":{\"capabilities\":[{\"name\":\"actions.capability.AUDIO_OUTPUT\"},{\"name\":\"actions.capability.SCREEN_OUTPUT\"},{\"name\":\"actions.capability.ACCOUNT_LINKING\"},{\"name\":\"actions.capability.WEB_BROWSER\"},{\"name\":\"actions.capability.MEDIA_RESPONSE_AUDIO\"}]},\"availableSurfaces\":[{\"capabilities\":[{\"name\":\"actions.capability.WEB_BROWSER\"},{\"name\":\"actions.capability.SCREEN_OUTPUT\"},{\"name\":\"actions.capability.AUDIO_OUTPUT\"}]}]}",
"delegatedRequest": {
"delegatedRequest": ""
}
},
"agentToAssistantDebug": {
"agentToAssistantJson": "<!DOCTYPE html><html lang=en><meta charset=utf-8><meta name=viewport content=\"initial-scale=1, minimum-scale=1, width=device-width\"><title>Error 400 (Not Found)!!1</title><style nonce=\"2YtDuE0THEDAcE3p1uuIgA\">*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{color:#222;text-align:unset;margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px;}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}pre{white-space:pre-wrap;}ins{color:#777;text-decoration:none}a img{border:0}#media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}#media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}#media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}</style><div id=\"af-error-container\"><a href=//www.google.com><span id=logo aria-label=Google></span></a><p><b>400.</b> <ins>That’s an error.</ins><p>The requested URL was not found on this server. <ins>That’s all we know.</ins></div>",
"delegatedResponse": {
"delegatedResponse": ""
}
},
"sharedDebugInfoList": [],
"conversationBuilderExecutionEventsList": []
},
"visualResponse": {
"visualElementsList": [
{
"displayText": {
"content": "MyAction Test isn't responding right now. Try again soon."
}
}
],
"suggestionsList": [],
"agentLogoUrl": ""
},
"clientError": 0,
"is3pResponse": true,
"clientOperationList": [
{
"operationType": 4,
"startIndicatorPayLoad": {
"status": 1
}
},
{
"operationType": 7,
"exitIndicatorPayLoad": {
"status": 1
}
}
],
"projectName": "",
"renderedHtml": ""
}
And the Stackdriver log is showing:
2019-09-12 11:56:49.381 BST App returned an HTTP error. State: URL_ERROR
{
insertId: "1iedwiug2dbgn68"
labels: {
channel: "preview"
querystream: "GOOGLE_USER"
source: "AOG_REQUEST_RESPONSE"
}
logName: "projects/myaction-test/logs/actions.googleapis.com%2Factions"
receiveTimestamp: "2019-09-12T10:56:49.389233862Z"
resource: {
labels: {…}
type: "assistant_action"
}
severity: "ERROR"
textPayload: "App returned an HTTP error. State: URL_ERROR"
timestamp: "2019-09-12T10:56:49.381445860Z"
trace: "projects/XXXXX/traces/ABXXXXX"
}
Looking at Dialogflow, the Environments / versions view shows the status of the release as "Deploying", so there seems to be a mismatch between the Action and Dialogflow deployments..?
I have tried re-releasing to Alpha (original attempt was nearly 4 hours ago), but the same problem/ errors still exist. Both attempted releases are showing as "Deploying" in Dialogflow.
Has anyone seen this before? Any idea what the problem may be or how to resolve it?
Thanks!
No solution yet but I have opened a support request with logs that have the same error.
Haven't received a support response yet but did find a workaround.
Inside of the Dialogflow agent settings > Environments and under draft I was able to view all versions. The latest version that I was looking for did say "Ready". When I clicked on the three dots to the right I loaded it to draft. Then in the Actions on Google console I went to Deploy, then the alpha section and clicked "Submit for alpha". Almost immediately after deploying and seeing "Deployed", the skill was available again for the alpha users.
Definitely don't remember doing this previously.
Finally got a response from Google who said there was an "issue" that day. Seems to be working OK now

Angular Using Wrong URL for querying MongoDB with NodeJS

I have this Angular 7 app that was working fine until I decided to move my logic out of the app.component.ts file into a new login.component.ts file. Ever since I did this, when I try and login and the app queries the database, it uses the wrong url--4200 instead of 3000. I set up a proxy.conf.json file like this:
{
"/api": {
"target": "http://localhost:3000",
"secure": false
}
}
This actually was already set up before I made the switch out of my app.component.ts file. I didn't make any other changes than reconnecting everything from the move to another component. I can't find where Angular is pointed to localhost:4200 instead of 3000. Does anyone have any ideas? Thanks in advance. Banging my head against the wall. By the by my OS is Windows 10 running VS Code.
Here's the error of my next issue:
VM623:37 ERROR TypeError: Cannot read property '0' of undefined
at
LoginComponent.push../src/app/login/login.component.ts.LoginComponent.toPrint
And here are the two functions involved with this error:
toPrint(match) {
return `Name: ${this.match[0].name} Checking: ${this.match[0].checking}
Savings: ${this.match[0].savings}`
}
printUserData(match){
this.buttonPressed = true;
return this.loginComponent.toPrint(match);
}
Just include your proxy configurations in angular.json file so that at the time when you run your application it run your proxy as well.
Example -
"serve": {
"builder": "#angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "movie-analysis:build",
"proxyConfig": "src/proxy.conf.json"
},
"configurations": {
"production": {
"browserTarget": "movie-analysis:build:production"
}
}
}
Hope it helps :)

Unable to host docker image from azure registry to azure batch

I am new to docker as well as azure batch. The problem i am having currently is i have 2 dotnet console applications one of them runs locally (which creates the pool, job and task on azure batch programmatically) and for second one i have created a docker image and pushed to azure container registry. Now the things is when i create the cloudtTask from locally running application as monetione below
TaskContainerSettings cmdContainerSettings = new TaskContainerSettings(
imageName: "myrepository.azurecr.io/pipeline:latest",
containerRunOptions: "--rm"
);
CloudTask containerTask = new CloudTask(
id: "task1",
commandline: cmdLine);
containerTask.ContainerSettings = cmdContainerSettings;
Console.WriteLine("Task created");
await batchClient.JobOperations.AddTaskAsync(newJobId, containerTask);
Console.WriteLine("-----------------------");
and add it to the BatchClient, the expcetion i get in azure batch (Azure portal) is this:
System.UnauthorizedAccessException: Access to the path '/home/_azbatch/.dotnet' is denied. ---> System.IO.IOException: Permission denied
--- End of inner exception stack trace ---
What can be the problem? Thank you.
As the comment ended up being the answer, I'm posting it here for clarity for future viewers:
The task needs to be run with elevated rights.
eg.
containerTask.UserIdentity = new UserIdentity(new AutoUserSpecification(elevationLevel: ElevationLevel.Admin, scope: AutoUserScope.Task));
See the docs for more info
i am still not able to pull image from docker, i am using nodejs .. following are configs for creating task
const taskConfig = {
"id": "task-new-2",
"commandLine": "bash -c 'node index.js'",
"containerSettings": {
"imageName": "xxx.xx.io/xx-test:latest",
"containerRunOptions": "--rm",
"username": "xxx",
"password": "tfDlZ",
"registryServer": "xxx.xx.io",
// "workingDirectory": "AZ_BATCH_NODE_ROOT_DIR"
},
"userIdentity": {
"autoUser": {
"scope": "pool",
"elevationLevel": "admin"
}
}
}

How to keep parse server and dashboard online?

i'm using parse server and parse dashboard for my push notification and DB stuffs, my problem is when i establish an ssh connection to my VPS and run them both everything is fine until i turn off my computer or disconnect from the server dashboard and parse server will terminated! is there any solution to make them online permanently?
commands i use:
for starting the parse server ->
npm start
for starting the parse dashboard ->
parse-dashboard --config config.json --allowInsecureHTTP
even i tried to duplicate nodejs running but it doesn't work.
Include the ParseDashboard inside your ParseServer. If you are using the parse-server-example, install parse-dasboard inside parse-server-example using npm install parse-dashboard and copy this inside index.js
var ParseDashboard = require('parse-dashboard');
var ParseServer = require('parse-server').ParseServer;
var dashboard = new ParseDashboard({
"apps": [{
"serverURL": "https://yourserver.url",
"appId": "myAppId",
"masterKey": "myMasterKey",
"appName": "YourAppName"
}
],
"users": [{
"user": "user",
"pass": process.env.USER_PASS || "pass"
}]
}, allowInsecureHTTP);
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'myAppId',
masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
liveQuery: {
classNames: ["Post", "Comments"] // List of classes to support for query subscriptions
}
});
usually, whenever you exit your SSH session, your active session will be killed. Using screen command will create a session that will not be killed even you closed your terminal / exit SSH. And you can do exactly what you usually do.
described in this link:
https://github.com/ParsePlatform/parse-dashboard/issues/162
enter screen at SSH session.some instruction and info will display, dismiss it with spacebar. here you go, a new screen that will remain running even you exit your SSH session.you might run the following command:
cd /var/www/parse/parse-dashboard npm start --config some/path/to/parse-dashboard-config.json --allowInsecureHTTP=1
thanks to #cricket_007

Resources