无法在本地主机上加载服务器

时间:2017-03-21 01:55:44

标签: node.js

当我尝试在我的localhost上的端口上运行我的node.js脚本时,该页面只是尝试永久加载,但不会显示它应该显示的内容。这只是因为我的计算机无法处理运行脚本的事实吗?如果是这样,为了测试目的,如何解决这个问题。

    // setup express to configure a basic web server
 var express = require('express');
 var app = express();

 // moment.js is the preferred date library
 var moment = require('moment');

 // access Node.js Crypto library for signature generation
 var crypto = require('crypto');

 // use request or request-promise to call into STATS API
 var request = require('request');

 // respond to all get requests
 app.get('/', function (req, res) {
   // get the current time
   var timeFromEpoch = moment.utc().unix();

   // set the API key (this is the actual key)
   var apiKey = 'key';

   // set the shared secret key (actual shared secret hash key)
   var secret = 'secret';

   // generate signature
   var sig = crypto.createHash('sha256').update(apiKey + secret + timeFromEpoch).digest('hex');

   request('api:website',
       function (err, response, body) {
         // parse the body as JSON
         var parsedBody = JSON.parse(body);
         res.json(parsedBody);
       });
 });

 var port = 3001;
 app.listen(port, function () {
   console.log('Listening on port ' + port);

 // run this file (node [filename]) and go to http://127.0.0.1:3001

0 个答案:

没有答案