• 로그인
  • 장바구니에 상품이 없습니다.

vue sse

4 글 보임 - 1 에서 4 까지 (총 4 중에서)
  • 글쓴이
  • #34067

    김대호
    참가자

    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'));
        });

    이것때문에 그런건가요..?

    #34089

    codingapple
    키 마스터

    app.get('*',  그부분 주석처리해봅시다 

    #34090

    김대호
    참가자

    그러면 뷰 라우팅 어떻게 해야하나요..?

    #34154

    codingapple
    키 마스터

    그러네요 

    var cors = require('cors')
    app.use(cors());

    서버에 npm install cors 하고 위 코드 추가해봅시다 

4 글 보임 - 1 에서 4 까지 (총 4 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠