我有一個簡單的「門票」的模式,看起來像這樣:res.json不發送JSON響應
var mongoose = require('mongoose');
var alias = require('mongoose-aliasfield');
var ticketSchema = new mongoose.Schema({
d: { type: String, alias: 'description', required: true, trim: true },
t: { type: Date, alias: 'eventdate', required: true }
});
ticketSchema.plugin(alias);
module.exports = mongoose.model('Ticket', ticketSchema);
我試圖返回所有使用快速路由器現有門票JSON:
var router = require('express').Router();
var Ticket = require('../models/ticket');
router.get('/', function (req,res) {
Ticket.find({}, function(err, tickets) {
if (err) {
console.log(err.message);
return res.status(500).send();
}
return res.status(200).json(tickets);
});
});
出於某種原因,響應回來爲對象的數組以「text/html的」的內容類型:
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 1826
ETag: W/"722-szU3qBkszFjaLqHo4B0UZA"
Date: Tue, 17 May 2016 08:23:32 GMT
Connection: keep-alive
我相信我守ld回到json的Content-Type的「application/json」......我錯過了什麼?