NJS Questions and/or Bugs

Sergey A. Osokin osa at freebsd.org.ru
Thu Aug 12 02:40:42 UTC 2021


On Wed, Aug 11, 2021 at 09:31:41PM -0500, Lance Dockins wrote:
> Hi Sergey,
> 
...
> 
> dbadmin.js
> function access(r){
>     r.return(200, JSON.stringify(r.args));
> 
>     r.internalRedirect('@php');

Two points:
- missing return directive here;
- r.internalRedirect will never happend because of r.return above.

> }
> 
> export default {access}

Here's my code that works as expected:

function argskeyvalue(r) {
    var jObj = JSON.stringify(r.args) + '\n';

    try {
        var parseJSON = JSON.parse(jObj);
    } catch (err) {
        r.return(400, 'Cannot parse jObj');
        return;
    }

    r.return(200, jObj);

    return;
}

export default { argskeyvalue };

As you can see it creates a JSON object jObj, then test it's
parseable and if so return 200.

Hope that helps.

-- 
Sergey


More information about the nginx mailing list