无法在快速中间件函数内调试或命中断点

时间:2018-03-26 01:47:57

标签: javascript node.js express

我以为我之前有这个工作但是,即使在使webstorm的缓存无效之后,这仍然无效。就像标题所说,我在下面的陈述中无法击中任何断点。我在某处读到语句" 是一个赋值表达式,并且该函数没有在帧中调用,所以没有什么可以进入int o"。有没有办法重写这个,以便我可以调试?

const request = require('request');
const Feed = require('../models/feed');
const async = require('async');
const FeedParser = require('feedparser');
const {check, validationResult} = require('express-validator/check');
const {sanitizeParam} = require('express-validator/filter');
const feedParserOptions = {addmeta: 'false'};
const authorEndpoint = 'http://localhost:3000/authors/';
const debug = require('debug');


exports.createAuthor = [

check('firstName', 'First name must be specified').isLength({min: 1}).trim(),
check('lastName', 'Last name must be specified').isLength({min: 1}).trim(),
sanitizeParam('firstName').trim().escape(),
sanitizeParam('lastName').trim().escape(),


(req, res, next) => {
    const errors = validationResult(req);
    const author = new Author({
        firstName: req.query.firstName,
        lastName: req.query.lastName,
    });

    debug(req.query.firstName);
    if (errors.isEmpty()) {
        let query = {
            $or: [{firstName: {$regex: req.query.firstName, $options: 'i'}},
                {lastName: {$regex: req.query.lastName, $options: 'i'}}],
        }; // TODO this regex fails if a parameter is missing.


        Author.findOne(query).sort([['lastName', 'ascending']]).exec((err, existingAuthor) => {
            if (err) {
                return next(err);
            }

            if (!(existingAuthor == null)) {
                let result = {status: 'Author already exists: ', author_id: String(existingAuthor.id)};
                res.locals.messages = result;
                next();
            } else if (existingAuthor == null) {
                author.save(function(err, newAuthor) {
                    if (err) {
                        return next(err);
                    }

                    let result = {status: 'New author saved', author_id: String(newAuthor.id)};
                    res.locals.messages = result;
                    next();
                });
            }
        });
    }
},
];

0 个答案:

没有答案