router.get('/', (req, res) => { res.render('index', { apiUrl: req.apiGateway ? `https://${req.apiGateway.event.headers.Host}/${req.apiGateway.event.requestContext.stage}` : 'http://localhost:3000' }) })
/************************************ * HTTP post method for insert object * *************************************/ app.post(path, function(req, res) { if (userIdPresent) { req.body['userId'] = req.apiGateway.event.requestContext.identity.cognitoIdentityId || UNAUTH; } let putItemParams = { TableName: tableName, Item: req.body } dynamodb.put(putItemParams, (err, data) => { if(err) { res.json({error: err, url: req.url, body: req.body}); } else{ res.json({success: 'post call succeed!', url: req.url, data: data}) } }); });
if (userIdPresent && req.apiGateway) { params[partitionKeyName] = req.apiGateway.event.requestContext.identity.cognitoIdentityId || UNAUTH; } else { params[partitionKeyName] = req.params[partitionKeyName];
app.get('/ServerlessReactExample/:ID', function(req, res) { var condition = {} condition[partitionKeyName] = { ComparisonOperator: 'EQ' } if (userIdPresent && req.apiGateway) { condition[partitionKeyName]['AttributeValueList'] = [req.apiGateway.event.requestContext.identity.cognitoIdentityId || UNAUTH ]; } else { try { condition[partitionKeyName]['AttributeValueList'] = [ convertUrlType(req.params[partitionKeyName], partitionKeyType) ]; } catch(err) { res.json({error: 'Wrong column type ' + err}); } } let queryParams = { TableName: tableName, KeyConditions: condition } dynamodb.query(queryParams, (err, data) => { if (err) { res.json({error: 'Could not load items: ' + err}); } else { res.json(data.Items); } }); });
if (userIdPresent && req.apiGateway) { params[partitionKeyName] = req.apiGateway.event.requestContext.identity.cognitoIdentityId || UNAUTH; } else { params[partitionKeyName] = req.params[partitionKeyName];
/************************************ * HTTP put method for insert object * *************************************/ app.put(path, function (req, res) { if (userIdPresent) { req.body['userId'] = req.apiGateway.event.requestContext.identity.cognitoIdentityId || UNAUTH; } let putItemParams = { TableName: tableName, Item: req.body } dynamodb.put(putItemParams, (err, data) => { if (err) { res.statusCode = 500; res.json({ error: err, url: req.url, body: req.body }); } else { res.json({ success: 'put call succeed!', url: req.url, data: data }) } }); });
if (userIdPresent && req.apiGateway) { condition[partitionKeyName]['AttributeValueList'] = [req.apiGateway.event.requestContext.identity.cognitoIdentityId || UNAUTH]; } else { try {
router.get('/', (req, res) => { res.render('index', { apiUrl: req.apiGateway ? `https://${req.apiGateway.event.headers.Host}/${req.apiGateway.event.requestContext.stage}` : 'http://localhost:3000' }) })
/************************************ * HTTP post method for insert object * *************************************/ app.post(path, function (req, res) { if (userIdPresent) { req.body['userId'] = req.apiGateway.event.requestContext.identity.cognitoIdentityId || UNAUTH; } let putItemParams = { TableName: tableName, Item: req.body } dynamodb.put(putItemParams, (err, data) => { if (err) { res.statusCode = 500; res.json({ error: err, url: req.url, body: req.body }); } else { res.json({ success: 'post call succeed!', url: req.url, data: data }) } }); });
/************************************ * HTTP put method for insert object * *************************************/ app.put(path, function(req, res) { if (userIdPresent) { req.body['userId'] = req.apiGateway.event.requestContext.identity.cognitoIdentityId || UNAUTH; } let putItemParams = { TableName: tableName, Item: req.body } dynamodb.put(putItemParams, (err, data) => { if(err) { res.json({error: err, url: req.url, body: req.body}); } else{ res.json({success: 'put call succeed!', url: req.url, data: data}) } }); });
/************************************ * HTTP put method for insert object * *************************************/ app.put(path, function (req, res) { if (userIdPresent) { req.body['userId'] = req.apiGateway.event.requestContext.identity.cognitoIdentityId || UNAUTH; } let putItemParams = { TableName: tableName, Item: req.body } dynamodb.put(putItemParams, (err, data) => { if (err) { res.statusCode = 500; res.json({ error: err, url: req.url, body: req.body }); } else { res.json({ success: 'put call succeed!', url: req.url, data: data }) } }); });
/************************************ * HTTP post method for insert object * *************************************/ app.post(path, function (req, res) { if (userIdPresent) { req.body['userId'] = req.apiGateway.event.requestContext.identity.cognitoIdentityId || UNAUTH; } let putItemParams = { TableName: tableName, Item: req.body } dynamodb.put(putItemParams, (err, data) => { if (err) { res.statusCode = 500; res.json({ error: err, url: req.url, body: req.body }); } else { res.json({ success: 'post call succeed!', url: req.url, data: data }) } }); });
if (userIdPresent && req.apiGateway) { condition[partitionKeyName]['AttributeValueList'] = [req.apiGateway.event.requestContext.identity.cognitoIdentityId || UNAUTH]; } else { try {
if (userIdPresent && req.apiGateway) { params[partitionKeyName] = req.apiGateway.event.requestContext.identity.cognitoIdentityId || UNAUTH; } else { params[partitionKeyName] = req.params[partitionKeyName];
if (userIdPresent && req.apiGateway) { params[partitionKeyName] = req.apiGateway.event.requestContext.identity.cognitoIdentityId || UNAUTH; } else { params[partitionKeyName] = req.params[partitionKeyName];