Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response is missing a body #11

Open
marians opened this issue Dec 5, 2019 · 1 comment
Open

Response is missing a body #11

marians opened this issue Dec 5, 2019 · 1 comment

Comments

@marians
Copy link

marians commented Dec 5, 2019

Hi! I am getting a request through to searchkit-express, but the response contains no body. When I issue requests directly against ElasticSearch, things work as expected.

Here is my server:

var express = require('express');
var SearchkitExpress = require("searchkit-express")
var cors = require('cors');
var morgan = require('morgan')
var jwt = require('express-jwt');
var jwks = require('jwks-rsa');

var app = express()

var host = process.env.ELASTICSEARCH_URL || 'http://127.0.0.1:9200';
var port = process.env.PORT || 8080;
var index = process.env.ELASTICSEARCH_INDEX || 'documents';

var jwtCheck = jwt({
    secret: jwks.expressJwtSecret({
        cache: true,
        rateLimit: true,
        jwksRequestsPerMinute: 5,
        jwksUri: 'https://some-subdomain.auth0.com/.well-known/jwks.json'
  }),
  audience: 'my-audience-string>',
  issuer: 'https://some-subdomain.auth0.com/',
  algorithms: ['RS256']
});

app.use(morgan('combined'));
app.use(cors());
app.use(jwtCheck);

app.listen(port);

SearchkitExpress({
  host: host,
  index: index,
  queryProcessor: function(query, req, res) {
    if (req.method !== 'POST') {
      return null;
    }

    return query
  }
 }, app);

Debug log output:

  express:application set "x-powered-by" to true +0ms
  express:application set "etag" to 'weak' +1ms
  express:application set "etag fn" to [Function: generateETag] +0ms
  express:application set "env" to 'development' +1ms
  express:application set "query parser" to 'extended' +0ms
  express:application set "query parser fn" to [Function: parseExtendedQueryString] +0ms
  express:application set "subdomain offset" to 2 +0ms
  express:application set "trust proxy" to false +0ms
  express:application set "trust proxy fn" to [Function: trustNone] +0ms
  express:application booting in development mode +0ms
  express:application set "view" to [Function: View] +0ms
  express:application set "views" to '/Users/marian/git/myproject/views' +1ms
  express:application set "jsonp callback name" to 'callback' +0ms
  express:router use '/' query +3ms
  express:router:layer new '/' +0ms
  express:router use '/' expressInit +0ms
  express:router:layer new '/' +0ms
  express:router use '/' logger +0ms
  express:router:layer new '/' +0ms
  express:router use '/' corsMiddleware +0ms
  express:router:layer new '/' +1ms
  express:router use '/' middleware +0ms
  express:router:layer new '/' +0ms
  express:router:route new '/_search' +2ms
  express:router:layer new '/_search' +0ms
  express:router:route post '/_search' +0ms
  express:router:layer new '/' +0ms
  express:router use '/' router +0ms
  express:router:layer new '/' +0ms
  express:router dispatching OPTIONS /_search?rest_total_hits_as_int=true +10s
  express:router query  : /_search?rest_total_hits_as_int=true +1ms
  express:router expressInit  : /_search?rest_total_hits_as_int=true +3ms
  express:router logger  : /_search?rest_total_hits_as_int=true +0ms
  express:router corsMiddleware  : /_search?rest_total_hits_as_int=true +2ms
::ffff:127.0.0.1 - - [05/Dec/2019:17:13:46 +0000] "OPTIONS /_search?rest_total_hits_as_int=true HTTP/1.1" 204 0 "http://localhost:3000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
  express:router dispatching POST /_search?rest_total_hits_as_int=true +6ms
  express:router query  : /_search?rest_total_hits_as_int=true +0ms
  express:router expressInit  : /_search?rest_total_hits_as_int=true +0ms
  express:router logger  : /_search?rest_total_hits_as_int=true +0ms
  express:router corsMiddleware  : /_search?rest_total_hits_as_int=true +0ms
  express:router middleware  : /_search?rest_total_hits_as_int=true +0ms
  express:router router  : /_search?rest_total_hits_as_int=true +211ms
  express:router dispatching POST /_search?rest_total_hits_as_int=true +0ms
  SearchkitExpress Start Elastic Request http://127.0.0.1:9200/documents/_search +1ms
  SearchkitExpress Request body {} +0ms
  SearchkitExpress Finished Elastic Request http://127.0.0.1:9200/documents/_search 200 +22ms
::ffff:127.0.0.1 - - [05/Dec/2019:17:13:46 +0000] "POST /_search?rest_total_hits_as_int=true HTTP/1.1" 200 38985 "http://localhost:3000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"

NodeJS version: v12.12.0

The request body is supposed to be empty, as I am trying to retrieve all documents.

Any suggestion what I could do to debug the situation?

Thank you!

@marians
Copy link
Author

marians commented Dec 6, 2019

Found it. I missed the part using bodyParser from the README. body-parser has become a dependency to be installed and imported.

var bodyParser = require('body-parser');

...

app.use(bodyParser.json());

Seems to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant