From 125baa2710fc783f60869e183c2e91e87ab28ffc Mon Sep 17 00:00:00 2001 From: AceDataCloud Date: Tue, 21 Sep 2021 00:59:44 +0800 Subject: [PATCH] add publish page --- src/pages/content/article/Publish.vue | 8 +++++++- vite.config.ts | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/pages/content/article/Publish.vue b/src/pages/content/article/Publish.vue index bfe7d0fb..7d5c7696 100644 --- a/src/pages/content/article/Publish.vue +++ b/src/pages/content/article/Publish.vue @@ -12,17 +12,23 @@ interface IData { socket: WebSocket | undefined; inputValue: string; chatValue: string; + id: string; } export default defineComponent({ data(): IData { return { + id: this.$route.params.id.toString(), socket: undefined, inputValue: '', chatValue: '' }; }, mounted() { - this.socket = new WebSocket('ws://localhost:8000/ws/chat/1'); + this.socket = new WebSocket( + `${window.location.protocol === 'https:' ? 'wss://' : 'ws://'}/${window.location.host}/ws/publish/${ + this.id + }?access_token=${this.$store.getters.accessToken}` + ); this.socket.onmessage = this.onMessage; }, methods: { diff --git a/vite.config.ts b/vite.config.ts index f9d3c2c0..eb545011 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -11,6 +11,11 @@ export default defineConfig({ '/api': { target: 'http://localhost:8000', changeOrigin: true + }, + '/ws': { + target: 'ws://localhost:8000', + changeOrigin: true, + ws: true } } },