routes - 在 Fastify 中使用参数编写路由完整 URL
问题描述
有没有办法在 Fastify 中引用某个路由的完整路径?我的意思是如果我需要,考虑到服务器主机和过去的参数,得到它的完整路径。
我的情况:我有 2 条路线 - 上传和查看文件。
// Here is the module with my routes
const routes = async (fastify: FastifyInstance) => {
fastify.get('/file/:id', async (req, reply) => { // [1]
... // here a can view a file by id
});
fastify.post('/file', async (req, reply) => {
... // uploading a the file
const fileId = uploadFile.id;
const viewFileURL = ...; // [2] Here I need to reference on route [1]
return { success: true, src: viewFileURL };
});
}
在 POST 路由 (2) 中,我想编写一个 URL,以便在文件上传后立即查看文件。
我的最终目标是当用户上传文件时,他可以从响应中获取链接并访问它以检查上传的文件。
解决方案
推荐阅读
- ansible - 如何登录运行 Ansible 的遥控器?
- module - How to manage module dependencies in jq
- reactjs - 从一个 Webpack 配置输出多个 React 应用程序
- node.js - 在运行 grunt 时找不到模块“findup-sync”
- spring-boot - 为什么 Spring Boot 会为 Controller 方法参数验证抛出不同的异常?
- cakephp - Cakephp INNER JOIN (SELECT ... )
- powershell - 是否有一个 wa 来执行 PowerShell 脚本,然后在 (task.json) 中为自定义任务执行一个节点脚本?
- c - 将字段中的位扩展到掩码中的所有(重叠+相邻)设置位的最快方法?
- python - 在数据框中合并数据
- google-bigquery - 更简单的合并语句