Hello,
I created a hosted target following the tutorial. Using the Apigee Tutorial here(https://docs.apigee.com/api-platform/hosted-targets/hosted-targets-tutorials).There.There) was a section on creating a NodeJs/Express App on your machine and then uploading/deploying to Apigee Edge. I have that tutorial working perfectly well. All the get requests work fine. I can can access the req.params.
I also created a simple get request. This code works on my local machine. It will simply return the request body. The following code builds fine on Apigee.
app.get("/test", (req,res)=> {
res.send(req.body);
})
When I try to make a get request with a response body I get this error. If I do not have a response body, then I get the expected {}. I did this on postman, and curl I am getting the same results. When I try to trace it, the request is not captured and nothing is displayed. Things to note is that I have body-parser installed as a dependency and is on the package.json file.
Error:
<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 400 (Bad Request)!!1</title>
<style>
*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
</style>
<a href=//www.google.com/>
<span id=logo aria-label=Google></span>
</a>
<p>
<b>400.</b>
<ins>Thatâs an error.</ins>
<p>Your client has issued a malformed or illegal request.
<ins>Thatâs all we know.</ins>
Full Code :
app.yaml
runtime: node
runtimeVersion: 8
application: my-express-app
env:
- name: NODE_ENV
value: production
- name: LOG_LEVEL
value: 3
index.js
var express = require('express')
var app = express()
let bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.get('/', function(req, res) {
res.json({
hello: "Hello World!"
})
})
app.get('/hello/:name', function(req, res) {
var name = req.params.name
res.json({
hello: "hello " + name
})
})
//The only added code(get Request)
app.get("/test", (req,res)=> {
console.log(req.body)
res.send(req.body);
})
var server = app.listen(process.env.PORT || 9000, function() {
console.log('Listening on port %d', server.address().port)
})
package.json
{
"name": "hello-world",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "node index.js --use_strict"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"express": "^4.16.0"
},
"devDependencies": {},
"description": ""
}
TLDR: If I make an http request with a request body, I get the the error above.