{"id":1636,"date":"2022-01-02T18:00:23","date_gmt":"2022-01-02T09:00:23","guid":{"rendered":"https:\/\/dalomo.net\/blog\/?p=1636"},"modified":"2022-03-27T15:58:16","modified_gmt":"2022-03-27T06:58:16","slug":"%e7%b0%a1%e6%98%93%e6%8e%b2%e7%a4%ba%e6%9d%bf%e3%82%92%e4%bd%9c%e3%82%8a%e3%81%9f%e3%81%84%e3%80%81node-jsexpress%e3%81%a7-%e2%91%a6%e8%89%b2%e3%80%85","status":"publish","type":"post","link":"https:\/\/dalomo.net\/blog\/2022\/01\/02\/1636\/","title":{"rendered":"\u7c21\u6613\u63b2\u793a\u677f\u3092\u4f5c\u308a\u305f\u3044\u3001node.js+express\u3067 \u2466\u8272\u3005"},"content":{"rendered":"<h1>\u8272\u3005<\/h1>\n<p>\u601d\u3044\u3064\u3044\u305f\u3053\u3068\u3092\u8272\u3005\u3084\u3063\u3066\u3044\u304f\u3002<\/p>\n<h2>Helmet\u3092\u4f7f\u3046<\/h2>\n<p><a href=\"https:\/\/expressjs.com\/ja\/advanced\/best-practice-security.html#use-helmet\">https:\/\/expressjs.com\/ja\/advanced\/best-practice-security.html#use-helmet<\/a><\/p>\n<p>express\u3067\u63a8\u5968\u3055\u308c\u3066\u305f\u3002<\/p>\n<pre> $ npm install --save helmet<\/pre>\n<p>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u8ffd\u8a18<\/p>\n<pre><code class=\"js\">var helmet = require('helmet')\r\napp.use(helmet())<\/code><\/pre>\n<p>\u52b9\u679c\u306f\u3088\u304f\u5206\u304b\u3089\u306a\u3044\u3002<\/p>\n<p><a href=\"https:\/\/qiita.com\/qianer-fengtian\/items\/148602c437e1703aa764\">https:\/\/qiita.com\/qianer-fengtian\/items\/148602c437e1703aa764<\/a><\/p>\n<p>\u3068\u304b\u53c2\u7167\u3002<\/p>\n<h2>Javascript\u3067htmlspecialchars<\/h2>\n<p>PHP\u4f7f\u3063\u305f\u3068\u304d\u306a\u3093\u304b\u3053\u3093\u306a\u306e\u3042\u3063\u305f\u3088\u306a\u30fc\u3068\u601d\u3063\u3066\u63a2\u3057\u3066\u307f\u305f\u3089\u3001javascript\u3067\u306f\u306a\u3044\u3089\u3057\u3044\u3002\u306a\u306e\u3067\u81ea\u5206\u3067\u95a2\u6570\u4f5c\u3063\u3066\u5bfe\u5fdc\u3059\u308b\u305d\u3046\u306a\u3002\u3061\u3087\u3046\u3069Stackoverflow\u306b\u540c\u69d8\u306e\u8cea\u554f\u304c\u3042\u3063\u305f\u3002<\/p>\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/1787322\/what-is-the-htmlspecialchars-equivalent-in-javascript\">https:\/\/stackoverflow.com\/questions\/1787322\/what-is-the-htmlspecialchars-equivalent-in-javascript<\/a><\/p>\n<pre><code class=\"js\">function escapeHtml(text) {\r\n  return text\r\n      .replace(\/&amp;\/g, \"&amp;\")\r\n      .replace(\/&lt;\/g, \"&lt;\")\r\n      .replace(\/&gt;\/g, \"&gt;\")\r\n      .replace(\/\"\/g, \"\"\")\r\n      .replace(\/'\/g, \"'\");\r\n}<\/code><\/pre>\n<p>replace\u3067\u4e00\u500b\u305a\u3064\u7f6e\u304d\u63db\u3048\u3066\u304f\u3002<\/p>\n<h2>\u5165\u529b\u6587\u5b57\u6570\u30c1\u30a7\u30c3\u30af<\/h2>\n<p>\u672a\u5165\u529b\u3060\u306e\u3001\u9577\u3044\u3084\u3064\u3092\u5f3e\u304f\u3002<\/p>\n<pre><code class=\"js\">if (req.body['user_message'] === '') {\r\n      res.status(400).send('\u306a\u3044\u3088\u3046\u304c\u306a\u3044\u3088\u3046')\r\n      return;\r\n    }\r\n\r\n    if (req.body['user_message'].length &gt; 400) {\r\n      res.status(400).send('\u306a\u3044\u3088\u3046\u304c\u306a\u304c\u3044\u3088\u3046')\r\n      return;\r\n    }\r\n\r\n    if (req.body['user_name'].length &gt; 20) {\r\n      res.status(400).send('\u306a\u307e\u3048\u304c\u306a\u304c\u3044\u3088\u3046')\r\n      return;\r\n    }<\/code><\/pre>\n<p>\u9577\u3055\u898b\u3066\u308b\u3060\u3051\u3060\u306d\u3002<\/p>\n<h2>\u65b0\u3057\u3044\u6295\u7a3f\u304c\u4e0a\u306b\u6765\u308b\u3088\u3046\u306b\u3059\u308b<\/h2>\n<pre>data.reverse();<\/pre>\n<p>\u3053\u3093\u306a\u7c21\u5358\u306a\u306e\u3060\u306a\u3002\u305f\u3060\u7de8\u96c6\u2192\u66f4\u65b0\u3057\u305f\u3084\u3064\u306f\u4e0a\u306b\u6765\u306a\u3044\u3002<\/p>\n<h2>\u65e5\u6642\u3092GMT\u306b\u3059\u308b\u3001\u5f62\u5f0f\u3092\u5909\u3048\u308b<\/h2>\n<p><a href=\"https:\/\/developer.mozilla.org\/ja\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Intl\/DateTimeFormat\/DateTimeFormat\">https:\/\/developer.mozilla.org\/ja\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Intl\/DateTimeFormat\/DateTimeFormat<\/a><\/p>\n<p>\u3053\u3061\u3089\u306b\u66f8\u3044\u3066\u3042\u308b\u3053\u3068\u3092\u8aad\u307f\u89e3\u304d\u3064\u3064<\/p>\n<pre><code class=\"js\">function fmtdate(){\r\n  let o = new Intl.DateTimeFormat('jp-JP', {\r\n    weekday: 'narrow',\r\n    year: 'numeric',\r\n    month: '2-digit',\r\n    day: '2-digit',\r\n    hour: '2-digit',\r\n    minute: '2-digit',\r\n    second: '2-digit',\r\n    fractionalSecondDigits: 3\r\n  })\r\n\r\n  return o.format(new Date())\r\n}<\/code><\/pre>\n<p>\u3053\u3093\u306a\u95a2\u6570\u3092\u4f5c\u3063\u305f\u3002\u4eca\u307e\u3067<\/p>\n<blockquote><p>2022-01-02T11:50:36.446Z<\/p><\/blockquote>\n<p>\u3053\u3093\u306a\u8868\u793a\u3067UTC\u3060\u3063\u305f\u306e\u304c<\/p>\n<blockquote><p>2022\/01\/02(\u65e5) 20:51:07.812<\/p><\/blockquote>\n<p>\u3053\u3093\u306a\u8868\u793a\u3067GMT\u306b\u306a\u3063\u305f\u3002<\/p>\n<h2>\u3068\u308a\u3042\u3048\u305a\u7d42\u308f\u308a<\/h2>\n<p>\u3053\u3093\u306a\u3068\u3053\u308d\u304b\u306a\u3041\u3002\u3042\u3068\u6700\u7d42\u306e\u30bd\u30fc\u30b9\u3002<\/p>\n<p><!--nextpage--><\/p>\n<h2>\u7c21\u6613\u63b2\u793a\u677f nodebbs index.html\u30bd\u30fc\u30b9<\/h2>\n<p><script src=\"https:\/\/gist.github.com\/dalomo-net\/51676384036908baddfb74c60e6ba1f9.js\"><\/script><\/p>\n<p><!--nextpage--><\/p>\n<h2>\u7c21\u6613\u63b2\u793a\u677f nodebbs app.js\u30bd\u30fc\u30b9<\/h2>\n<p><script src=\"https:\/\/gist.github.com\/dalomo-net\/d3f26719a83f800832117a5078184288.js\"><\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8272\u3005 \u601d\u3044\u3064\u3044\u305f\u3053\u3068\u3092\u8272\u3005\u3084\u3063\u3066\u3044\u304f\u3002 Helmet\u3092\u4f7f\u3046 https:\/\/expressjs.com\/ja\/advanced\/best-practice-security.html#use-helmet express &hellip; <a href=\"https:\/\/dalomo.net\/blog\/2022\/01\/02\/1636\/\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[8,2],"tags":[132,130,157],"class_list":["post-1636","post","type-post","status-publish","format-standard","hentry","category-8","category-2","tag-express","tag-node-js","tag-157"],"_links":{"self":[{"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/posts\/1636","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/comments?post=1636"}],"version-history":[{"count":4,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/posts\/1636\/revisions"}],"predecessor-version":[{"id":1640,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/posts\/1636\/revisions\/1640"}],"wp:attachment":[{"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/media?parent=1636"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/categories?post=1636"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dalomo.net\/blog\/wp-json\/wp\/v2\/tags?post=1636"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}