访问TVDB数据库时出现/ POST错误

时间:2017-04-28 01:17:44

标签: javascript node.js express

我正在将tvdb数据库用于项目。使用我现在的代码,我无法从数据库中获取任何数据。当我发布请求时,除非我手动取消请求,否则请求永远不会结束。它是apikey还是客户端没有正确构建。请帮忙。

app.js

var express = require('express');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');

var TVDB = require('node-tvdb');

var Show = require('../models/shows');
var Episode = require('../models/episodes');

var showRouter = express.Router();

showRouter.use(bodyParser.json());

showRouter.route('/')
    .get(function(req, res, next){
        var query = Show.find();
        if (req.query.genre) {
            query.where({ genre: req.query.genre });
        } else if (req.query.alphabet) {
            query.where({ name: new RegExp('^' + '[' + req.query.alphabet + ']', 'i') });
        } else {
            query.limit(12);
        }
        query.exec(function(err, shows) {
            if (err) return next(err);
            res.send(shows);
        });
    })

.post(function(req, res, next) {
  var apiKey = '5BB799C77561B167';

  var tvdb = new TVDB(apiKey);
  var seriesName = req.body.showName;
  //only for test, data not yet created in
  //mongodb
  tvdb.getSeriesByName(seriesName, function(err, series){
    if(err) throw err;
    res.send(series.data.series || series.data.series[0]);
  });
});

showRouter.route('/:_id')
    .get(function(req, res, next) {
        Show.findById(req.params._id, function(err, show) {
            if (err) return next(err);
            res.send(show);
        });a
    });

module.exports = showRouter;

showRouter.js

var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var showSchema = new Schema({
    _id: Number,
    name: String,
    airsDayOfWeek: String,
    airsTime: String,
    firstAired: Date,
    genre: [String],
    network: String,
    overview: String,
    rating: Number,
    ratingCount: Number,
    status: String,
    banner: String,
    subscribers: [{
        type: mongoose.Schema.Types.ObjectId, 
        ref: 'User'
    }],
    episodes: [{
        type: mongoose.Schema.Types.ObjectId, 
        ref: 'Episode'
    }]
});

var Show = mongoose.model('Show', showSchema);
module.exports = Show;

shows.js

Options +FollowSymLinks

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

0 个答案:

没有答案