Tuesday 15 July 2014

web services - Node.js parameters not passed correctly to router -


I am new to node. I have server.js, router.js, index.js and requestHandler.js files in my project. I get pathName from url and pass it in router. I

  http : // localhost: 8888 / start   

js server like below:

server.js:

  var http = key Required ("http"); Var url = requirement ("url"); Start the function (route, handle) {function on request (request, response) {var pathname = url.parse (request.url) .path name; Console.log ("Request for" + pathname + "received"); Route (handle, path name); Response.writeHead (200, {"content type": "text / plain"}); Response.write ("Hello World"); Response.end (); } Http.createServer (onRequest) .listen (8888); Console.log ("The server has started."); } Export.start = start;   

router.js:

  function path (handle, pathname) {console.log ("for request about path" + pathname); If (type operation [pathname] === 'function') {handle [pathname] (); } Else {console.log ("A request handler" + found for pathname); }} Export.route = Route;   

index.js:

  var server = (". / Server"); Var router = is required ("./ router"); Var RequestsHandlers = Required ("./ requestHandler"); Var handle = {} handle ["/"] = requesthands Start; Handle ["/ start"] = requestHandlers.start; ["/ Upload"] = requestHandlers.upload handle; Server.start (router.route, handle);   

requestHandler.js:

  Start the function () {console.log ("Request Handler Start".); } Upload function () {console.log ("Request handler was called 'upload.'); } Export.start = start; Export.upload = upload;   

I get the wrong result:

  psc: \ program files \ nodejs & gt; Node .. \. \ User \ personal \ desktop \ hello \ index.js server has started. Regarding a Request for Receipt / Receipt / About a request for / for efavicon.ico No request handler for unspecified request No about the route / request for request for favicon.ico Handler Not found / undefined request received for /vavicon.ico To request a route for /favicon.ico, no request handler has been found for the server instead of   

 . Requested / Received Route for request / handler was called 'start' for a request to start.   

What's the problem? Any ideas?

I tried to code my code on my machine (MACS X + v0.8.9). This works fine. There is a console output:

  The request for request / receive root for the server started / was called 'start' for a request to start the handler. Request for / Favicon.ico About the route received / request for favicon.ico / no request handler for /vavicon.ico was not found   

It is difficult why you face error Did you have to do the node version check?

From your log data, the problem is in the function root (handle, path name) the value of the pathname defined in router.js "/ start" Can be undefined from. You may have to debug this function to find out the reasons.

No comments:

Post a Comment