node.js - 如何将 ?url= 更改为节点结构化路由
问题描述
所以我目前正在做以下事情。
http://example.com/podcast?url=https://storage.googleapis.com/radiomediapodcast/QWA/S01/QWAS1E1.mp3
但是,我想做以下事情。
http://example.com/podcast/https://storage.googleapis.com/XXX/XXX/S01/QWAS1E1.mp3
我知道这router.get('/:url', (req, res) => {
应该允许我发送http://example.com/podcast/http
我也明白
router.get('/:url*', (req, res) => {
还应该允许http://example.com/podcast/https://storage.googleapis.com/XXX/XXX/S01/QWAS1E1.mp3 `
解决方案
*
可以为您的 url 调用路由,并且可以req.params
让您读取随之传递的内部 url。
尝试以下路线http://example.com/podcast/https://storage.googleapis.com/XXX/XXX/S01/QWAS1E1.mp3
router.get('/prodcast/*', async (req, res, next) => {
console.log(req.query.params); //https://storage.googleapis.com/XXX/XXX/S01/QWAS1E1.mp3
res.status(200).send('ok');
});
推荐阅读
- python - 数据框转移python熊猫
- python - 如何使用 Selenium Python 单击链接问题
- flutter - 如何在按下时立即更改图标按钮颜色(颤动)
- c# - Add custom XML using C# VSTO addon
- save - 如何将每个图像保存到 jupyter notebook 上这个数组的文件夹中?
- java - 将 StringBuilder 输出直接转换为 InputSream
- intellij-idea - 如何在 IntelliJ IDEA 中为 Ktor 设置运行配置?
- f# - 如何限制列表中的线程数
F# 中的 .asParallel - javascript - 检查是否从具有相同类 javascript 的输入中选择了至少一个单选按钮
- macos - Visual Studio for Mac 不会创建按钮单击处理程序