以下是我的 nginx 配置
server {
listen 443 ssl http2;
listen [::]:443 http2 ssl;
server_name www.mydomain.com;
ssl_certificate /etc/letsencrypt/live/www.mydomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.mydomain.com/privkey.pem;
access_log off;
location / {
proxy_pass http://127.0.0.1:3000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_buffering off;
proxy_cache off;
proxy_read_timeout 300s;
chunked_transfer_encoding off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
我的服务端代码
eventRouter.get('/event/:userID', async (req, res) => {
const headers: OutgoingHttpHeaders = {
'Content-Type': 'text/event-stream',
'Connection': 'keep-alive',
"Cache-Control": 'no-cache',
"X-Accel-Buffering": 'no'
}
res.writeHead(200, headers)
res.write(JSON.stringify({ type: 'handshake' } satisfies IEventMessage))
}
有知道的大佬吗,实在不行我滚回 long-loop 了