Fix CORS issue

This commit is contained in:
tdgmcode 2023-03-15 02:37:23 -04:00
parent f55b202014
commit a63661a088
7 changed files with 584 additions and 20 deletions

View file

@ -2,8 +2,12 @@ import { Server } from 'socket.io'
import { backendProxy } from '../lib/db/db.js'
function configureServer(server) {
const io = new Server(server.httpServer)
const io = new Server(server, {
cors: {
origin: '*',
}
});
io.on('connection', (socket) => {
socket.on('join', async (id) => {
socket.join(id);

View file

@ -1,5 +1,6 @@
<script>
import { io } from 'socket.io-client'
import { dev } from '$app/environment';
import PostBody from '$lib/components/PostBody.svelte';
/** @type {import('./$types').PageData} */
@ -9,13 +10,21 @@
let messages = [];
let input;
const socket = io();
let socket;
if (dev) {
socket = io('http://localhost:7272/');
} else {
socket = io('http://ws.tdgmdev.net/');
}
socket.emit('join',id);
function scroll() {
setTimeout(function() {
input.lastChild.scrollIntoView()
if (input && input.lastChild)
input.lastChild.scrollIntoView()
},200);
}