my nodejs application was running successfully on digital ocean server but it post request stop working once i deploy it to amazon aws server
$http.post(base+url, form, {
method : 'POST',
crossDomain: true,
json: true,
headers:{'Content-Type': 'application/json'}
}
it it was running successfully on digital ocean server
$http.post(base+url, form, {
method : 'POST',
crossDomain: true,
json: true,
headers:{'Content-Type': 'application/x-www-form-urlencoded'}
}
app.use(function (req, res, next) {
res.header('Access-Control-Allow-Headers', '*');
// add details of what is allowed in HTTP request headers to the response headers
res.header('Access-Control-Allow-Origin', req.headers.origin);
// res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Methods', '*');
// res.header('Access-Control-Allow-Credentials', false);
res.header('Access-Control-Max-Age', '586400');
// the next() function continues execution and will move onto the requested URL/URI
next();
});
i am new in amazon please help me to run my code in amazon aws as it was running in digital ocean
router.route('/login')
.post(function (req, res) {
// was post method
//req.body = req.query;
var async = require('async');
var utils = require('utility/utils'),
db_query = require('db_query/query'),
constant = require("config/constant");
var response_data = {};
async.series([
function(callback) {
var validate = require('utility/validate');
validate.validateSignin(req,res,function(){
callback();
})
},
function(callback){
var crypto = require('crypto'),
userName = req.body.username,
password = req.body.password;
var selection = '*',
table = constant.USER_MASTER_TABLE;
var condition = [{
"name" : "userName",
"type" : constant.VARCHAR50,
"value" : userName
},{
"name" : "userPwd",
"type" : constant.VARCHAR50,
"value" : password
}];
db_query.selectFromDb(req,res,condition,selection,table,response_data,function(){
if(response_data.details.length>0)
{
if(response_data.details[0].UserActiveStatus == constant.ACTIVE_STATUS)
{
response_data.user_details = response_data.details;
callback();
}
else
{
response_data.success = false;
response_data.message = "Please Enter active Username and Password.";
res.status(203).send({response_data});
}
}
else
{
response_data.success = false;
response_data.message = "Please Enter valid Username and Password.";
res.status(203).send({response_data});
}
})
},
function(callback)
{
utils.createAuthentication(res,res,response_data.details[0],function(token){
response_data.token = token;
callback();
})
},
function(callback)
{
var table = constant.USER_MASTER_TABLE;
var fieldlist = [
{
"name" : "userLastLogin",
"type" : constant.DATE_TIME,
"varname" : "SYSDATETIME()",
"value" : null
}];
var condition = [{
"name" : "userId",
"type" : constant.SMINT,
"value" : response_data.details[0].userId
}];
db_query.updateToDb(req,res,condition,fieldlist,table,response_data,function(){
callback();
});
}
],function(err) {
response_data.success = true;
response_data.message = "successfully login!";
res.status(200).send({response_data});
});
});
1) Left panel -> (In Network and Security) -> Security groups
2) Select the security group for your current instance.
3) In the Actions Dropdown -> Click Edit inbound rules.
4) Select Type as "All Traffic" and source as "Anywhere".
5) Click Save.
That should do it.
## my problem was i was using ##
res.header('Access-Control-Allow-Headers', '*');
##i replace it with ##
res.header('Access-Control-Allow-Headers', 'application/json');
it start working
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.