Deployed Node.js application to bluemix, error : cannot find concept-insights-devoxx.mybluemix.net/css/style.css - node.js

The style.css lives in public/css folder and config/express.js has
app.use(express.static(__dirname + '/../public'));
Still I am getting the following error
Please help , Thanks, Sandhya

I don't think your missing css is the problem. It would just mess up your styling on the page.
The TypeError above that seems more to the point. An object property "offsetTop" was referred to, but the object doesn't actually exist (or something that was supposed to create it, didn't return anything).
I'd guess that might have been what caused the 502 error, or perhaps the other way around (i.e. a proper response could not be received from the api call, and for some reason that case was not considered by whoever wrote the logic that comes after that).
Do you have the relevant code that you could post perhaps?

Thanks for the answer! The problem was in manifest.yml, where I was binding to a different instance of Concept Insights service. Therefore, the credentials given in app.js for the instance of Concept Insights populated with my corpus were getting overwritten.
Thanks for looking at this issue !
Sandhya

Related

Implementing authentication with passport / node.js and getting error

I had already implemented authentication for the app I'm working on but am trying to refactor it based on a recent tutorial I did which I thought was very clear and also involved adding facebook / google / twitter auth which I would like to do.
So far, I've updated the user model and defined my local strategy for signup but when I go to try and run the app now, I'm getting an error. I have the app uploaded to github and wondered if somebody would be able to check it out and see where I'm going wrong. The error is pointing to a part of the index file until node_modules / express but I cannot work out what's up and I'd like to know before I proceed further.
Latest commit is under: https://github.com/DaveBage83/friendly-invention
Thanks!
A few things for you notice.
1 - Do not commit the node_modules folder. Once you have all your dependencies in the package.json file, the npm install will download all of for you again.
2 - This code is full of erros. I won't put everything here, I believe you find them by yourself. Otherwise, put the specific code here, so we can help you out.
About the question:
In you app.js file.
...
authRoutes = require('./routes/index')(app, passport)
...
If you look at the ./routes/index, you'll see that it is exporting a route object, witch does not expect the two parameters. (e.g. (app, passport)).
Hope it can still help you.

Error in setting up swagger in expressjs project

I have followed [this][1] link to add swagger to my existing project. I encountered the following error while setting up swagger. Any leads will be highly appreciated.
:xxx\node_modules\swagger-node-express\Common\node\
swagger.js:84
self.appHandler.get(self.resourcePath.replace(self.formatString, self.jsonSuff
ix), resourceListing);
^TypeError: Cannot read property 'get' of null
[1]: https://github.com/shawngong/Swagger-Node-Express-For-Existing-APIs
This error is popping out because of -
var applicationUrl = 'http://localhost:9000'; //application runs properly on this url
swagger.configure(applicationUrl, '1.0.0');//error here
Looking at the line of code in question node-swagger-express it seems as if you need to call :
swagger.setAppHandler(app);
Before the configure call.
I specifically see the maintainer of the project you are using (https://github.com/shawngong/Swagger-Node-Express-For-Existing-APIs) has a commit message related to setAppHandler in his last commit. Perhaps there is now an issue related to it.

Why do I get "Invalid token" unless I invert projectId and clientId?

In order to setup Google Identity Toolkit for my Website I started with the Quick-start App for Node.js.
It worked fine on localhost.
But when I moved it to an actual app-engine instance it did not work anymore.
I got this error returned by gitkitClient.verifyGitkitToken():
Invalid token: Unable to verify the ID Token: Wrong recipient, payload
audience != requiredAudience
I found a very helpful post on stackoverflow about more or less the same issue, for Java instead of node.js: It looks like there is a mismatch between projectId and clientId.
I changed my gitkit-server-config.json file to swap the projectId and clientId values and it worked!
This sound very much like a major bug on google side, doesn't it?
Why does it work on localhost?
Will this be changed/fixed in the future?
Maybe the problem is in the tutorial?
I have a working solution for now, but I do not feel safe to keep it like that...
I hope a googler will read this!
[EDIT]
Following wyhao31's comment I had a closer look at the gitkitclient.js source code and both projectId and clientId are added to the same audiences array.
After more test I found out that you must only put the project ID ('my-project-name') in the gitkit-server-config.json file.
The nasty thing is that if you add it with a 'clientId' property name it is also working...
Based on your description, and if you read gitkit-server-config.json file like this
var gitkitClient = new GitkitClient(JSON.parse(fs.readFileSync('./gitkit-server-config.json')));
I think the problem might caused by using old nodejs client lib. Could you try to update your client lib to latest version(0.0.6)? Or you can use the code directly.

How to use the ChromeApp to connect to a node.js server?

I have a Node.js server and I'd like to know how I could do for the ChromeApp to work with it. I tried putting "http://localhost:3000" (server address) on the runtime:
chrome.app.runtime.onLaunched.addListener(function () {
chrome.app.window.create('http://localhost:3000');
});
But it doesn't even launch. Does someone have an idea on what I could do?
Thanks.
You cannot launch external URLs with chrome.app.window.create. In fact if you check the chrome.runtime.lastError property you will see the following error:
The URL used for window creation must be local for security reasons.
I suggest you look into using the <webview> tag as it is much more appropriate for your use-case.

Proper way to handle errors in ExpressJS 3

I've been struggling for the past hours trying to find a decent tutorial on how to handle errors for a NodeJS + ExpressJS 3 api.
I've read a lot of questions/answers on SO and read the official ExpressJS guide and still cannot figure out the proper way to do such an important thing. Most of the answers I found were relevant in Express 1 or Express 2, but are not anymore and the ExpressJS Guide just describes something out of context, which makes it really hard to understand.
So here's my use case : I want to get informations about a city, using the GET /cities/:slug. If the slug doesn't exist or an error happened (with MongoDB or Mongoose for example), I want to return an error code.
Here's the relevant part of my current code :
if (err || !city) {
res.json({code:500, city:[]});
}
It's a basic example and it's working "well", but I'm pretty sure that's not the right way to do it in NodeJS.
Also, this does not stop my NodeJS instance, but some unexpected errors might. From what I read, this is not a problem in production because apparently restarting the NodeJS instance is cleaner, and third-parties handle it pretty well (read about Cluster, Forever or even Monit).
Would love to have more insights on this problem I've been overlooking for too long.

Resources