Giter Site home page Giter Site logo

Comments (4)

indexzero avatar indexzero commented on August 20, 2024

Maybe you don't have permission to listen on that port? What is the code you're testing?

from api-easy.

tciuro avatar tciuro commented on August 20, 2024

It's a node.js server that's working fine (I'm actually testing it with Objective-C and Chrome's Dev HTTP Client utility. I'm running on port 8080 without issues:

9 Jul 00:09:02 - [nodemon] starting `node app.js localhost 8080`
Express HTTP server listening on port 8080

Assuming that the server is running fine, the above code would report a 403 as opposed to permission denied, right? Or is this permission denied the result of an HTTP 403? (which the server returns if no authentication has succeeded)

Thank you.

from api-easy.

tciuro avatar tciuro commented on August 20, 2024

I'm having no trouble at all performing the invocation from the browser. Weird...

from api-easy.

tciuro avatar tciuro commented on August 20, 2024

OK, somehow I got it to work (I've tried so many things I'm not sure what made it work.) This is the dummy test I setup in place:

function showStats(req, res) {

  log.info('GET /admin/stats');

  var someValue = '12345';
  res.writeHead(200, {
    'Content-Type': 'application/json',
  });
  res.write(JSON.stringify({
    someValue: someValue
  }));
  return res.end();
}

module.exports.initialize = function (app) {
  app.get('/admin/stats', showStats);
};

This is the test:

var APIeasy = require('api-easy'),
  assert = require('assert');

var suite = APIeasy.describe('your/awesome/api');

suite.discuss('When using your awesome API')
  .discuss('and your awesome resource')
  .use('localhost', 8080)
  .setHeader('Content-Type', 'application/json')
  .get('/admin/stats')
  .expect(200)
  .export(module);

When I call npm test, I get the following:

Macintosh:fooTest tito$ npm test
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No readme data.

> [email protected] test /Users/tito/Desktop/fooTest
> vows test/*-test.js

✗  

    When using your awesome API and your awesome resource A GET to /admin/stats 
      ✗ should respond with 200 
        » expected 200, 
    got  400 (==) // api-easy.js:290 
  ✗ Broken » 1 broken (1.330s) 
  npm ERR! weird error 1
npm ERR! not ok code 0
Macintosh:fooTest tito$ 

How in the world is it getting a 400? It's impossible! Again, if I invoke it via http://localhost:8080/admin/stats I get back:

{
    "someValue":"12345"
}

Even Charles proxy shows that the response is a 200. What gives?

from api-easy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.