目前在做 fastify 的时候遇到了一个没有解决办法的问题。
这是当前使用的代码。用户.js
async function routes(fastify, options) {
// GET /users/:id
fastify.get("/:id", async (req, res) => {
// Create a remote request to any url for testing
// https://jsonplaceholder.typicode.com/todos/1
});
}
module.exports = routes;
我想向以下 URL 发出请求并返回其响应。这就是我正在尝试的方式。
async function routes(fastify, options) {
// GET /users/:id
fastify.get("/:id", async (req, res) => {
// Create a remote request to any url for testing
// https://jsonplaceholder.typicode.com/todos/1
const response = await got;
fetch("https://jsonplaceholder.typicode.com/todos/1")
.then(response => response.json())
.then(json => {
console.log(json);
res.send({
id: req.params.id,
title: json.title,
completed: json.completed,
userId: json.userId
});
}).catch = err => {
console.log(err);
};
});
}
module.exports = routes;