module.exports.login = function (request, response, next) {
if (request.body.user && request.body.password) {
response.end('submitted');
} else {
common.render('login', function (error, file) {
if (error) {
next(error);
} else {
response.writeHead(200, 'OK', { 'Content-Type': 'text/html' });
var stream = fs.createReadStream(file);
stream.pipe(response);
}
});
}
};
我正在使用connect
body-parser
。当我第一次打开这个应用程序时,我看到登录表单 - 很好,但是当我提交表单时,我在控制台中看到405方法不允许错误。我试图添加一些标题,但它不起作用。有人可以帮忙吗?
答案 0 :(得分:0)
我认为语法应该是:
module.exports = function(request, response, next) {
if (request.body.user && request.body.password) {
response.end('submitted');
} else {
common.render('login', function (error, file) {
if (error) {
next(error);
} else {
response.writeHead(200, 'OK', { 'Content-Type': 'text/html' });
var stream = fs.createReadStream(file);
stream.pipe(response);
}
});
}
};
或
function login(request, response, next) {
if (request.body.user && request.body.password) {
response.end('submitted');
} else {
common.render('login', function (error, file) {
if (error) {
next(error);
} else {
response.writeHead(200, 'OK', { 'Content-Type': 'text/html' });
var stream = fs.createReadStream(file);
stream.pipe(response);
}
});
}
};
module.exports = login;
答案 1 :(得分:0)
我终于解决了它。问题是WITH first_posts AS (
SELECT p.id AS post_id, COUNT(c.id) AS comment_id, p.user_id, p.body, p.created_at
FROM (SELECT * FROM posts ORDER BY id LIMIT 3) AS p
LEFT JOIN comments AS c
ON p.id = c.post_id
GROUP BY 1, 3, 4, 5
)
SELECT post_id, comment_id, user_id, body, created_at
FROM (
SELECT 1 AS type, post_id, comment_id, user_id, body, created_at, 0 AS r
FROM first_posts
UNION ALL
SELECT 2 AS type, p.post_id, c.id, c.user_id, c.body, c.created_at,
ROW_NUMBER() OVER (PARTITION BY p.post_id ORDER BY c.id) AS r
FROM first_posts AS p
INNER JOIN comments AS c
ON p.post_id = c.post_id
ORDER BY post_id, type, comment_id
) AS f
WHERE r <= 3;
和serve-static
。它写了一些额外的标题,如允许的方法!