Category: Web

  • SSE Server Sent Events

    WebSocket 双向、复杂
    SSE 单向(server=>client)、简单、HTTP

    服务端设置

    res.setHeader(‘Content-Type’, ‘text/event-stream’);

    你要真正理解这几个点:

    Content-Type 必须是:
    text/event-stream
    不能被缓存
    Cache-Control: no-cache
    连接不能关闭
    Connection: keep-alive
    服务器是一直 write,不是 return

    https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events

  • fortio

    fortio load -qps 100 -n 100 https://weechoapp.com/shop_v2/api/cart/quantity?type=Product

  • G Suite 使用技巧

    公司使用 G Suite

    自己也有 google 账号,切换账号的 default

    https://support.google.com/accounts/thread/6368872?hl=en&msgid=6678524
    

    gmail settings, 关闭 chat, 打开 shortcuts

  • watch进行持续输出

    用 watch 在测试的时候可以跟进输出

    每一秒钟刷新一次

    watch -n 1 'netstat -nat | grep 211.148.19.12'

    如果想要持续性的查看,可以写到日志中

    watch -n1 'netstat -nat | grep 211.148.19.12| tee -a netstat.log'

    或者使用 sleep 来输出每一次的执行

    while sleep 1; do netstat -nat | grep 211.148.19.12; done
  • 记录指定状态码的 nginx log

    在 server 里配置,记录 403 的日志

    server {
        server_name example.com;
        access_log /var/log/nginx_access_403.log combined;
        include block_inject.conf;
        location / {
            if ($status != "403") {
                access_log off;
            }
            #......
        }
    }
    
  • nginx判断cookie 和 user-agent 跳转到 pc 或 m 站

    如果用户的 cookie 中已经访问过 m 站,或使用手机端的时候,跳转到手机端

            if ($cookie_mobile = "1") {
                rewrite ^ http://m.example.com/ redirect;
            }
            if ($http_user_agent ~* "android|iphone|ipod|windows\sphone") {
                rewrite ^ http://m.example.com/ redirect;
            }