Giter Club home page Giter Club logo

Comments (8)

mayorbyrne avatar mayorbyrne commented on May 18, 2024

Went from a 400 error to a 404 error. Using both cREST and node. No other details, just a plain 404 error.

var ruley = {
     ALL: [
        {'/api/v4/(.*)$':'api.cfm?v=4&fn=$1'}
    ]
   }
var jsonrule = JSON.stringify(ruley);
console.log(jsonrule);

    // REWRITE RULES: POST /host/<domain.com>/<port>/rule
    it('POST a URL rewrite',function(done){

        client.POST(root+'/host/'+props.hostname+'/'+props.port+'/rule', {json:jsonrule}, function(err,res,body){
        //parseInt(res.statusCode).should.equal(201);
        console.log(res.statusCode); //this reads 404
        })
    //  done();
    });

note the commented lines. this is purposely done so it times out and prints the statusCode.

if i run the following, the test passes (even though it actually returns a 404), AND the statusCode is never printed to the console.

    it('POST a URL rewrite',function(done){

        client.POST(root+'/host/'+props.hostname+'/'+props.port+'/rule', {json:ruley}, function(err,res,body){
        parseInt(res.statusCode).should.equal(201);
        console.log(res.statusCode);
        })
        done();
    });

from ngn.

coreybutler avatar coreybutler commented on May 18, 2024

In your last code snippet, the done() is not a part of the callback. It should be:

it('POST a URL rewrite',function(done){

        client.POST(root+'/host/'+props.hostname+'/'+props.port+'/rule', {json:ruley}, function(err,res,body){
            parseInt(res.statusCode).should.equal(201);
            console.log(res.statusCode);
            done(); // <--- Moved to here
        })
        // From Here
    });

A 404 is only returned when the endpoint doesn't exist. So, I'm not sure why you're seeing that... might help to post a gist of your code.

from ngn.

coreybutler avatar coreybutler commented on May 18, 2024

Sorry... a 404 can show up when the endpoint doesn't exist, but more importantly, it will show up when <domain.com> cannot be found.

I'll see what I can do about separating these return codes. I think a 400 or bad request makes more sense if the endpoint doesn't exist. The 404 makes sense when the domain is missing or does not exist.

from ngn.

mayorbyrne avatar mayorbyrne commented on May 18, 2024

I simply cannot get it to POST a rewrite rule. For giggles, I set up a web server running the simple eventionary on port 2500. My proxy is running on port 7770, and when I do localhost:7770, I am able to see the eventionary in the browser (so I know the domain.com is being found). I can GET and DELETE rules using a REST client, but when I try to POST a valid JSON rule, it still gives me a 404.

from ngn.

coreybutler avatar coreybutler commented on May 18, 2024

I believe the problem is the documentation. The great laptop genocide of October 3rd (where 3 laptops died) appears to have caused some loss in a few updates... not in the code, but the docs. The endpoint you're currently using, which is POST <base>/host/<hostname.com>/rule should actually be POST <base>/host/<hostname.com>/rule/<method> where <method> is the HTTP verb (GET, POST, PUT, DELETE) or ALL. The body is a single rule, like:

{"regex_pattern":"substitute"}

I'm reopening this until the documentation reflects these changes.

from ngn.

mayorbyrne avatar mayorbyrne commented on May 18, 2024

Ah ok, that makes sense. Unfortunately, I believe the problem persists.
I tried POSTing

{"/v9":"api9.html"}

to

/host//port/rule/GET

I get a 400 "Missing attribute: pattern and/or substitute" still.

from ngn.

mayorbyrne avatar mayorbyrne commented on May 18, 2024

furthermore, when I view (GET) the list of hosts, the "pattern" section of each rule is simply { }, only the substitute is shown. so, even though the cache.json file says:

                "ALL": [
                    {
                        "/api/v3/(.*)$": "api.cfm?v=3&fn=$1"
                    }
                ]

the JSON output of the GET method looks like

                "ALL": [
                    {
                        "pattern": {},
                        "substitute": "api.cfm?v=3&fn=$1",
                        "path": null,
                        "last": false,
                        "rewritten": false,
                        "acceptMethod": [
                            "GET",
                            "POST",
                            "PUT",
                            "DELETE",
                            "HEAD",
                            "TRACE"
                        ]
                    }
                ]

from ngn.

coreybutler avatar coreybutler commented on May 18, 2024

There was an issue parsing the body of the POST, which has been fixed in the master branch.

Also, I had a typo in my last comment. The endpoint for creating a rule is

CORRECT: POST <base>/host/<hostname.com>/<port>/rule/<method>
Incorrect: POST <base>/host/<hostname.com>/rule/<method> (port is missing).

from ngn.

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.