{"action":"closed","issue":{"url":"https://api.github.com/repos/hapijs/hapi/issues/3182","repository_url":"https://api.github.com/repos/hapijs/hapi","labels_url":"https://api.github.com/repos/hapijs/hapi/issues/3182/labels{/name}","comments_url":"https://api.github.com/repos/hapijs/hapi/issues/3182/comments","events_url":"https://api.github.com/repos/hapijs/hapi/issues/3182/events","html_url":"https://github.com/hapijs/hapi/issues/3182","id":157252970,"number":3182,"title":"Server hangs on POST request","user":{"login":"nodox","id":7632841,"avatar_url":"https://avatars.githubusercontent.com/u/7632841?v=3","gravatar_id":"","url":"https://api.github.com/users/nodox","html_url":"https://github.com/nodox","followers_url":"https://api.github.com/users/nodox/followers","following_url":"https://api.github.com/users/nodox/following{/other_user}","gists_url":"https://api.github.com/users/nodox/gists{/gist_id}","starred_url":"https://api.github.com/users/nodox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodox/subscriptions","organizations_url":"https://api.github.com/users/nodox/orgs","repos_url":"https://api.github.com/users/nodox/repos","events_url":"https://api.github.com/users/nodox/events{/privacy}","received_events_url":"https://api.github.com/users/nodox/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/hapijs/hapi/labels/question","name":"question","color":"d4c5f9"}],"state":"closed","locked":false,"assignee":{"login":"devinivy","id":3150233,"avatar_url":"https://avatars.githubusercontent.com/u/3150233?v=3","gravatar_id":"","url":"https://api.github.com/users/devinivy","html_url":"https://github.com/devinivy","followers_url":"https://api.github.com/users/devinivy/followers","following_url":"https://api.github.com/users/devinivy/following{/other_user}","gists_url":"https://api.github.com/users/devinivy/gists{/gist_id}","starred_url":"https://api.github.com/users/devinivy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devinivy/subscriptions","organizations_url":"https://api.github.com/users/devinivy/orgs","repos_url":"https://api.github.com/users/devinivy/repos","events_url":"https://api.github.com/users/devinivy/events{/privacy}","received_events_url":"https://api.github.com/users/devinivy/received_events","type":"User","site_admin":false},"milestone":null,"comments":1,"created_at":"2016-05-27T17:17:20Z","updated_at":"2016-05-27T17:40:01Z","closed_at":"2016-05-27T17:40:01Z","body":"Yesterday I have my server working perfectly. I did not touch any working server logic. Today my server doesn't accept POST requests. The server just hangs infinitely. I don't understand how my code can break while I'm not working on it. Can anyone help me debug this problem?\r\n\r\n\r\n```\r\n'use strict';\r\n\r\nconst path = require('path'),\r\n      controller = require(path.join(__dirname, '../controllers/sessions.js'));\r\n\r\nmodule.exports = [\r\n  {\r\n    method: 'POST',\r\n    path: '/login',\r\n    handler: controller.create\r\n  }\r\n]\r\n\r\n```\r\n\r\n\r\n```\r\n'use strict'\r\n\r\nconst JWT = require('jsonwebtoken'),\r\n      path = require('path'),\r\n      User = require( path.join(__dirname, '../models/user.js')),\r\n      Boom = require('boom');\r\n\r\nmodule.exports = {\r\n  create: (req, res) => {\r\n    const errors = {\r\n      emailError: 'email is required',\r\n      passwordError: 'password is required'\r\n    };\r\n\r\n    if (req.payload) {\r\n      ['email', 'password'].forEach( field => {\r\n        if (!req.payload[field])\r\n          return res(Boom.badData(errors[`${field}Error`]));\r\n      });\r\n\r\n      User.findOne({\r\n        email: req.payload.email\r\n      }).then((user) => {\r\n        if ( user && user.authenticate(req.payload.password)) {\r\n          user.token = JWT.sign({id: user.id}, 'xxx');\r\n          user.save().then( _ => {\r\n            return res({token: user.token});\r\n          });\r\n        } else {\r\n          return res(Boom.unauthorized('invalid credentials'));\r\n        }\r\n      }, (error) => {\r\n        return res(Boom.badImplementation(error));\r\n      });\r\n    }\r\n  }\r\n}\r\n\r\n```\r\n\r\n```\r\n'use strict';\r\n\r\nconst Hapi = require('hapi');\r\n\r\nconst server = new Hapi.Server();\r\nconst User = require('./models/user.js');\r\nconst JWT = require('jsonwebtoken');\r\nconst jwtAuth = require('hapi-auth-jwt');\r\nconst Boom = require('boom');\r\nconst mongoose = require('mongoose');\r\nconst routes = require('./routes');\r\n\r\nmongoose.connect('mongodb://localhost:27017/kard', _ => {\r\n  server.connection({\r\n    host: 'localhost',\r\n    port: 8080\r\n  });\r\n\r\n  const validate = (decoded, req, cb) => {\r\n    let err;\r\n    User.findOne({_id: decoded._id }, function(err, user) {\r\n      if (err) throw err;\r\n\r\n      if (!user) {\r\n        return cb(err, false);\r\n      }\r\n\r\n      req.user = user;\r\n      return cb(err, true);\r\n    });\r\n  };\r\n\r\n\r\n  server.register(require('hapi-auth-jwt2'), (err) => {\r\n    server.auth.strategy('token', 'jwt', {\r\n      key: 'xxx',\r\n      validateFunc: validate,\r\n    });\r\n  });\r\n\r\n  routes.forEach(route => server.route(route) );\r\n\r\n  const options = {\r\n    reporters: {\r\n        console: [{\r\n            module: 'good-squeeze',\r\n            name: 'Squeeze',\r\n            args: [{ log: '*', response: '*' }]\r\n        }, {\r\n            module: 'good-console'\r\n        }, 'stdout'],\r\n        file: [{\r\n            module: 'good-squeeze',\r\n            name: 'Squeeze',\r\n            args: [{ ops: '*' }]\r\n        }, {\r\n            module: 'good-squeeze',\r\n            name: 'SafeJson'\r\n        }, {\r\n            module: 'good-file',\r\n            args: ['./log/development.log']\r\n        }],\r\n        http: [{\r\n            module: 'good-squeeze',\r\n            name: 'Squeeze',\r\n            args: [{ error: '*' }]\r\n        }, {\r\n            module: 'good-http',\r\n            args: ['http://prod.logs:3000', {\r\n                wreck: {\r\n                    headers: { 'x-api-key': 12345 }\r\n                }\r\n            }]\r\n        }]\r\n    }\r\n  };\r\n\r\n  server.register({ register: require('good'), options }, (err) => {\r\n    if (err) throw err;\r\n  });\r\n\r\n\r\n  // Allow angular to handle routing on the the frontend\r\n  server.register(require('inert'), (err) => {\r\n\r\n    if (err) {\r\n      throw err;\r\n    }\r\n\r\n    /** \r\n     * FIXME: Add robust production setup\r\n     */\r\n    server.route({\r\n      method: 'GET',\r\n      path: '/{param*}',\r\n      handler: {\r\n        directory: {\r\n          path: 'dist'\r\n        }\r\n      }\r\n    });\r\n\r\n    server.start((err) => {\r\n\r\n      if (err) {\r\n        throw err;\r\n      }\r\n\r\n      console.log('Server running at ', server.info.uri);\r\n    });\r\n  });\r\n\r\n});\r\n```"}}
{"actor":{"display_login":"devinivy"}}