vue
created() {
this.$store.dispatch('owner_customer_update');
},
store.js
owner_customer_update() {
var eventSource = new EventSource('/aaa');
eventSource.addEventListener('test', function (e) {
console.log(e.data);
});
},
server.js
app.get('/aaa', function (요청, 응답) {
응답.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
Connection: 'keep-alive',
});
응답.write('event: test\n');
응답.write('data: abc\n\n');
});
이렇게 하면 계속
EventSource's response has a MIME type ("text/html") that is not "text/event-stream". Aborting the connection.
이런오류가 나타나더라구요
그래서 네트워크 들어가서 보니
요청헤더는
Accept:
text/event-stream
인데
응답헤더는
Content-Type:
text/html; charset=UTF-8
이여서 문제인거같은데
index.html meta에 http-equiv="Content-Type"
content="text/event-stream"
charset="utf-8"
해도
안되네요..
app.get('*', function (요청, 응답) {
응답.sendFile(path.join(__dirname, '/notwait/dist/index.html'));
});
이것때문에 그런건가요..?