feat: add Vite proxy, change terminal to other channel

This commit is contained in:
wancat committed 2023-08-21 20:40:05 +08:00
1 parent c3e735b627
commit c248004484
5 files changed
+11 -8

No files matched your search

+1
View File
@@ -19,6 +19,7 @@ onMounted(async () => {
socket.on('disconnect', function close() {
console.log('Disconnected from the server.')
})
socket.on('message', console.log)
})
</script>
+2 -2
View File
@@ -55,11 +55,11 @@ onMounted(() => {
term.open(terminal.value)
term.focus()
resizeScreen()
socket.on('message', (message) => {
socket.on('terminal', (message) => {
term.write(message)
})
term.onData((key) => {
socket.send(key)
socket.emit('terminal', key)
})
})
</script>
+1 -1
View File
@@ -1,7 +1,7 @@
import axios from 'axios'
const api = axios.create({
baseURL: 'https://odyssey.wancat.cc/api/v1',
baseURL: '/api',
})
export default api
+1 -3
View File
@@ -1,7 +1,5 @@
import io from 'socket.io-client'
const host = 'wss://odyssey.wancat.cc'
class SocketWrapper {
constructor() {
this.socket = null
@@ -14,7 +12,7 @@ class SocketWrapper {
this.socket.disconnect()
}
this.socket = io(host, {
this.socket = io('', {
query: {
session_id: session._id,
},
+6 -2
View File
@@ -7,8 +7,12 @@ export default defineConfig({
server: {
proxy: {
'/api': {
// target: 'http://localhost:3000', // the server url
target: 'http://odyssey.wancat.cc ',
target: 'http://localhost:3000/api/v1',
rewrite: (path) => path.replace(/^\/api/, ''), // Optional: remove "/api" prefix from the path
},
'/socket.io': {
target: 'ws://localhost:3000',
// target: 'wss://odyssey.wancat.cc',
ws: true,
},
},