connect

“Cannot GET /” with Connect on Node.js

依然范特西╮ 提交于 2019-11-27 11:39:06
I'm trying to start serving some static web pages using connect like this: var connect = require("connect"); var nowjs = require("now"); var io = require("socket.io"); var app = connect.createServer( connect.static(__dirname + '/public') ); app.listen(8180); So I added a simple index.html at the /public directory on the same directory as the app.js file is, but when I try to view the page on my browser I get this response from node: Cannot GET / What I'm doing wrong and how I can correct it? This code should work: var connect = require("connect"); var app = connect.createServer().use(connect

When to use next() and return next() in Node.js

白昼怎懂夜的黑 提交于 2019-11-27 10:17:19
Scenario : Consider the following is the part of code from a node web app. app.get('/users/:id?', function(req, res, next){ var id = req.params.id; if (id) { // do something } else { next(); //or return next(); } }); Issue : I am checking which one to go with just next() or return next() . Above sample code works exactly the same for both & did not show any difference in execution. Question : Can some one put light on this, when to use next() and when to use return next() and some important difference? Some people always write return next() is to ensure that the execution stops after

What are “signed” cookies in connect/expressjs?

霸气de小男生 提交于 2019-11-27 10:15:41
I am trying to figure out what "signed cookies" actually are. There isn't much on the net, and if I try this: app.use(express.cookieParser('A secret')); But still... Cookies are still 100% normal on the browser, and I don't really know what "signed" is here (I was sort of hoping to "see" some weirdness on the client, something like the data encrypted using "A secret" as salt?) The documentation says ( https://github.com/expressjs/cookie-parser ): Parse Cookie header and populate req.cookies with an object keyed by the cookie names. Optionally you may enabled signed cookie support by passing a

Java URLConnection Timeout

折月煮酒 提交于 2019-11-27 06:47:50
I am trying to parse an XML file from an HTTP URL. I want to configure a timeout of 15 seconds if the XML fetch takes longer than that, I want to report a timeout. For some reason, the setConnectTimeout and setReadTimeout do not work. Here's the code: URL url = new URL("http://www.myurl.com/sample.xml"); URLConnection urlConn = url.openConnection(); urlConn.setConnectTimeout(15000); urlConn.setReadTimeout(15000); urlConn.setAllowUserInteraction(false); urlConn.setDoOutput(true); InputStream inStream = urlConn.getInputStream(); InputSource input = new InputSource(inStream); And I am catching

How i can get user email and name with Facebook connect new platform

房东的猫 提交于 2019-11-27 06:29:23
问题 i am using facebook connect with new platform in my asp.net web site which is in 2.0. i want to get user email and name. how i can do that. Regards. 回答1: Email address and other information of user from Facebook, with users permission Before this you should have Facebook app id and secret id , these values can be created from below link, when you are logged into facebook https://developers.facebook.com/apps follow steps to create apps and you will keys automatically Step 0 make a test.php and

How to disable Express BodyParser for file uploads (Node.js)

戏子无情 提交于 2019-11-27 06:08:33
This seems like it should be a fairly simple question, but I'm having a really hard time figuring out how to approach it. I'm using Node.js + Express to build a web application, and I find the connect BodyParser that express exposes to be very useful in most cases. However, I would like to have more granular access to multipart form-data POSTS as they come - I need to pipe the input stream to another server, and want to avoid downloading the whole file first. Because I'm using the Express BodyParser, however, all file uploads are parsed automatically and uploaded and available using "request

Node.js / Express.js - How to override/intercept res.render function?

孤人 提交于 2019-11-27 04:23:59
问题 I'm building a Node.js app with Connect/Express.js and I want to intercept the res.render(view, option) function to run some code before forwarding it on to the original render function. app.get('/someUrl', function(req, res) { res.render = function(view, options, callback) { view = 'testViews/' + view; res.prototype.render(view, options, callback); }; res.render('index', { title: 'Hello world' }); }); It looks like a contrived example, but it does fit in an overall framework I'm building. My

Node / connect issue Object function createServer has no method static [duplicate]

∥☆過路亽.° 提交于 2019-11-27 03:04:43
问题 This question already has an answer here: “Cannot GET /” with Connect on Node.js 10 answers I'm trying to launch my node server using an example from an AngularJS book (server.js). var connect = require('connect'); connect.createServer( connect.static("../angularjs") ).listen(5000); Initially I was getting "object has no method static" so I re-installed the connect include and now when I do: node server.js I get a blinking cursor in CMD (Windows) and "Cannot GET /" from my browser. Any ideas

Java URLConnection - When do I need to use the connect() method?

别来无恙 提交于 2019-11-27 03:02:56
问题 I have a problem to understand the meaning of the connect() method in the URLConnection class. In the following code, if I use the connect() method, I get the same result if I don't use it. Why (or when) do I need to use it? URL u = new URL("http://example.com"); HttpURLConnection conn = (HttpURLConnection) u.openConnection(); conn.connect();//with or without it I have the same result InputStream in = conn.getInputStream(); int b; while ((b = in.read()) != -1) { System.out.write(b); } 回答1:

Is it possible to set a base URL for NodeJS app?

纵然是瞬间 提交于 2019-11-27 03:02:49
I want to be able to host multiple NodeJS apps under the same domain, without using sub-domains (like google.com/reader instead of images.google.com). The problem is that I'm always typing the first part of the url e.g. "/reader" in Express/NodeJS. How can I set up an Express app so that the base URL is something.com/myapp ? So instead of: app.get("/myapp", function (req, res) { // can be accessed from something.com/myapp }); I can do: // Some set-up app.base = "/myapp" app.get("/", function (req, res) { // can still be accessed from something.com/myapp }); I'd also like to configure Connect's