Add bodyParser calls for urlencoded and json request content-types
This commit is contained in:
@@ -8,9 +8,13 @@ const bodyParser = require('body-parser');
|
|||||||
|
|
||||||
// Command line opts
|
// Command line opts
|
||||||
const argv = require('minimist')(process.argv.slice(1));
|
const argv = require('minimist')(process.argv.slice(1));
|
||||||
if (!argv.codepath || !argv.port) {
|
if (!argv.codepath) {
|
||||||
console.error("Need --codepath and --port");
|
console.log("Codepath defaulting to /user.js");
|
||||||
process.exit(1);
|
argv.codepath = "/user.js";
|
||||||
|
}
|
||||||
|
if (!argv.port) {
|
||||||
|
console.log("Port defaulting to 8888");
|
||||||
|
argv.port = 8888;
|
||||||
}
|
}
|
||||||
|
|
||||||
// User function. Starts out undefined.
|
// User function. Starts out undefined.
|
||||||
@@ -44,7 +48,10 @@ function specialize(req, res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
app.use(bodyParser.urlencoded());
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
|
app.use(bodyParser.raw());
|
||||||
|
|
||||||
app.post('/specialize', specialize);
|
app.post('/specialize', specialize);
|
||||||
|
|
||||||
// Generic route -- all http requests go to the user function.
|
// Generic route -- all http requests go to the user function.
|
||||||
@@ -56,7 +63,7 @@ app.all('/', function (req, res) {
|
|||||||
const context = {
|
const context = {
|
||||||
request: req,
|
request: req,
|
||||||
response: res
|
response: res
|
||||||
// TODO: context should also have: URL template params, query string, ...anything else?
|
// TODO: context should also have: URL template params, query string
|
||||||
};
|
};
|
||||||
function callback(status, body, headers) {
|
function callback(status, body, headers) {
|
||||||
if (!status)
|
if (!status)
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
module.exports = function (context, callback) {
|
module.exports = function (context, callback) {
|
||||||
console.log("Test function entered");
|
console.log("headers=", JSON.stringify(context.request.headers));
|
||||||
callback(200, "Hello, world!\n");
|
console.log("body=", JSON.stringify(context.request.body));
|
||||||
console.log("Test function exit");
|
|
||||||
|
//console.log(`Test function entered: ${context.request.body}`);
|
||||||
|
|
||||||
|
callback(200, "Hello, world !\n");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user