Here is the express code
app.post('/v1/sessions' function(req,res){
res.send({id:1234});
});
For some reason the json response comes back like this
OK{ id: 1234}
Why is the OK there?
EDIT
Ok so here is all of my code. I don't see where it would be sending the OK.
var express = require('express');
var app = express();
app.enable('trust proxy');
app.use(express.bodyParser());
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next();
});
app.post('/v1/sessions', function(req, res) {
if(req.body.email == 'testuser@captusr.com' && req.body.password == 'testpass'){
res.send(200, JSON.stringify({token:{id:'longstring',email:'testuser@captusr.com'}}));
} else {
res.send({code:403, error:"Invalid email or password"});
}
});
app.all('*', function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'HEAD, GET, POST, PUT, DELETE, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, X-Requested-With, Origin, Accept');
res.header('Access-Control-Allow-Credentials', 'true');
if (req.method.toLowerCase() === 'options') {
res.send(200);
} else {
next();
}
});
app.listen(3000);
console.log('Listening on port 3000');
Can you replace this line:
res.send(200, JSON.stringify({token:{id:'longstring',email:'testuser@captusr.com'}}));
with this and see if that solves it. Express does the 200 and JSON.stringify for you, so don't re-do it.
res.send({token:{id:'longstring',email:'testuser@captusr.com'}});