1
タグがスペースで提出されると、そのスペースはレスポンスで%20として表示されます。リクエストとレスポンスのどちらにも、どのように各スペースを書き直すと、ダッシュになりますか?このための信頼できるライブラリはありますか?ありがとう!URLノードエクスプレスでのParamリライト
ルート
router.get('/search/:tag', function(req, res) {
const tag = req.params.tag;
tag.toLowerCase();
shopify.article.list(86289414)
.then(function (response) {
response.reverse();
response = response.map(function(element) {
return {
author: element.author,
blog_id: element.blog_id,
body_html: element.body_html,
created_at: element.created_at,
handle: element.handle,
id: element.id,
image: element.image,
published_at: element.published_at,
summary_html: element.summary_html,
tags: element.tags.toString().toLowerCase(),
template_suffix: element.template_suffix,
title: element.title,
updated_at: element.updated_at,
user_id: element.user_id
}
})
response = response.filter(function(item) {
return item.tags.indexOf(tag) > -1;
});
var data = {
articles: response.map((article) => {
return {
author: article.author,
id: article.id,
html: article.body_html,
tags: article.tags.split(","),
date: moment(article.published_at).format("Do MMM YYYY"),
slug: article.handle,
title: article.title,
} // return
}) // map
} // data
console.log(data);
res.render('blog-tags' , data);
}) // then
.catch(err => console.log(err))
});
%20が出現するのは確かです。 url/blog/Leak Sensorをクリックすると、ブラウザーに/ blog/Leak%20Sensorが返されます。私は私のポストを編集しました、私は両方の方法で動作する必要があることを認識しています。 – Quesofat
@Quesofat URLはHTTPプロトコルを壊すため、実際の領域を含めることはできません。そのため、サーバーはどこにあるかによって%20または+(aプラス)のスペースを常に取得します。したがって、すべてのスペースは、URLに含まれていると常にエンコードされます。 – rsp
唯一のことは、ルートの開始後にタグをログに記録するときに、スペースでログ記録することです。このソリューションはスペースであっても機能しますか?それは%20と仮定しているので、それはそのようには見えません。 – Quesofat