fastify ejs mongodb don;
我正在创建一个网站,目前我正在使用MongoDB进行数据库系统,但我几乎完成了该系统,但是自从我更新了一个快速套件以来,该页面仅显示白色,而另一个带有数据的EJS页面则带有数据发送
我的软件包: 快速:4.0.3 路径:0.12.7 @fastify/view:7.0.0 MongoDB:4.7.0 Dotenv:16.0.1 EJS:3.1.8 @fastify/static:6.4.0 @fastify/formbody:7.0.1 fastify-plugin:3.0.1 Mongoose:6.4.0
我的路线代码:
fastify.get("/result", async function (request, reply) {
let search = request.query.search;
if (search) {
await dbAnime.find({ aliases: search })
.toArray(async function (err, have) {
if (!err) {
if (have.length > 0) {
reply.view("/pages/result.ejs", { results: have }).then(() => {
console.log("replied")
});
console.log(have);
client.close;
} else {
reply.view("/pages/result.ejs", { results: have });
}
} else {
reply.code(400)
console.error(err);
}
});
};
});
和我的EJS页面:
<!DOCTYPE html>
<html data-theme="">
<head>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/card.css">
<link rel="preconnect" href="https://fonts.googleapis.com/">
<link rel="preconnect" href="https://cdn.glitch.global/">
<link rel="preconnect" href="https://cdn.discordapp.com/">
<link rel="icon" type="image/png" href=""/>
<title><%= results.length %> Résultat</title>
</head>
<body>
<div class="form-container">
<form class="form" action="/result">
<input id="myInput" type="text" class="input" name="search" placeholder="Rechercher un anime..."/>
</form>
</div>
<h2>Résultat: <%= results.length %></h2>
<% results.forEach(function(result){%>
<div class="paper" id="paper"><img class="poster" src="<%= result.image %>"/>
<h1><%= result.title %></h1>
<hr/>
<p><%= result.synopsis %></p><a class="btn" href="/info?animeName=<%= result.title %>">En savoir plus</a>
<div class="space"></div>
</div>
<% }); %>
</body>
</html>
我的控制台没有任何错误,那么我不知道如何修复它
I am creating a website and I am currently making a database system with mongodb, which I have almost finished but, since I updated a fastify package, the page only displays of white, same with another ejs page with data sended
My package:
fastify: 4.0.3
path: 0.12.7
@fastify/view: 7.0.0
mongodb: 4.7.0
dotenv: 16.0.1
ejs: 3.1.8
@fastify/static: 6.4.0
@fastify/formbody: 7.0.1
fastify-plugin: 3.0.1
mongoose: 6.4.0
My route code:
fastify.get("/result", async function (request, reply) {
let search = request.query.search;
if (search) {
await dbAnime.find({ aliases: search })
.toArray(async function (err, have) {
if (!err) {
if (have.length > 0) {
reply.view("/pages/result.ejs", { results: have }).then(() => {
console.log("replied")
});
console.log(have);
client.close;
} else {
reply.view("/pages/result.ejs", { results: have });
}
} else {
reply.code(400)
console.error(err);
}
});
};
});
and my ejs page:
<!DOCTYPE html>
<html data-theme="">
<head>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/card.css">
<link rel="preconnect" href="https://fonts.googleapis.com/">
<link rel="preconnect" href="https://cdn.glitch.global/">
<link rel="preconnect" href="https://cdn.discordapp.com/">
<link rel="icon" type="image/png" href=""/>
<title><%= results.length %> Résultat</title>
</head>
<body>
<div class="form-container">
<form class="form" action="/result">
<input id="myInput" type="text" class="input" name="search" placeholder="Rechercher un anime..."/>
</form>
</div>
<h2>Résultat: <%= results.length %></h2>
<% results.forEach(function(result){%>
<div class="paper" id="paper"><img class="poster" src="<%= result.image %>"/>
<h1><%= result.title %></h1>
<hr/>
<p><%= result.synopsis %></p><a class="btn" href="/info?animeName=<%= result.title %>">En savoir plus</a>
<div class="space"></div>
</div>
<% }); %>
</body>
</html>
i don't have any error in console, then i don't know how to fix it
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
异步函数和回复都有混合使用。
在Fastify V4中,如果要使用
send
方法,则必须返回回复
对象。我将更改代码如下:
There is a mix of async function and reply.send usages.
In Fastify v4 you must return the
reply
object if you want to use thesend
method.I would change the code as follows: