소스 검색

:construction: save work

Song 5 년 전
부모
커밋
fc95aa647c
3개의 변경된 파일18개의 추가작업 그리고 20개의 파일을 삭제
  1. 1 18
      README.md
  2. 15 0
      nginx.conf
  3. 2 2
      utils.js

+ 1 - 18
README.md

@@ -9,24 +9,7 @@
 3. 安装依赖:`npm i`。
 4. 安装 pm2:`npm i -g pm2`。
 5. 使用 Nginx 反代我们的 Node.js 服务,默认端口 3000。
-    1. 在 `/etc/nginx/site-enabled/` 目录下创建文件 `wechat-push-service.conf`(主配置文件 nginx.conf 内要有 `include /etc/nginx/sites-enabled/*.conf;`):
-        ```conf
-        server {
-            listen 443 ssl http2;
-            listen [::]:443 ssl http2;
-            server_name 你的域名;
-        
-            location / {
-                proxy_pass http://localhost:3000;  # 注意如果你改变了默认端口,记得在这里进行更新
-                proxy_http_version 1.1;
-                proxy_set_header Upgrade $http_upgrade;
-                proxy_set_header Connection 'upgrade';
-                proxy_set_header Host $host;
-                proxy_set_header X-Forwarded-For $remote_addr;
-                proxy_cache_bypass $http_upgrade;
-            }
-        }
-        ```
+    1. 修改应用根目录下的 `nginx.conf` 中的域名以及端口号,并创建软链接:`sudo ln -s ./nginx.conf /etc/nginx/site-enabled/wechat-push-service.conf` 
     2. 之后使用 [certbot](https://certbot.eff.org/lets-encrypt/ubuntuxenial-nginx) 申请证书:`sudo certbot --nginx`。
     3. 重启 Nginx 服务:`sudo service nginx restart`。
 

+ 15 - 0
nginx.conf

@@ -0,0 +1,15 @@
+server {
+    listen 443 ssl http2;
+    listen [::]:443 ssl http2;
+    server_name 你的域名;
+
+    location / {
+        proxy_pass http://localhost:3000;  # 注意如果你改变了默认端口,记得在这里进行更新
+        proxy_http_version 1.1;
+        proxy_set_header Upgrade $http_upgrade;
+        proxy_set_header Connection 'upgrade';
+        proxy_set_header Host $host;
+        proxy_set_header X-Forwarded-For $remote_addr;
+        proxy_cache_bypass $http_upgrade;
+    }
+}

+ 2 - 2
utils.js

@@ -11,7 +11,7 @@ module.exports = {
         if (res.data && res.data.access_token) {
           console.log("Token requested.");
           token = res.data.access_token;
-          app.access_token = token;
+          app.locals.access_token = token;
         } else {
           console.error(res.data);
         }
@@ -21,7 +21,7 @@ module.exports = {
 
   pushMessage: function (req, res, content) {
     // Reference: https://mp.weixin.qq.com/debug/cgi-bin/readtmpl?t=tmplmsg/faq_tmpl
-    let access_token = req.app.access_token;
+    let access_token = req.app.locals.access_token;
     let request_data = {
       touser: process.env.OPEN_ID,
       template_id: process.env.TEMPLATE_ID,