Rush
Rush
Explore posts from servers
NNuxt
Created by Rush on 11/13/2024 in #❓・help
Pinia problem
thank you, that solved my problem
12 replies
NNuxt
Created by Rush on 11/13/2024 in #❓・help
Pinia problem
don't I also need to install pinia and not just @pinia nuxt?
12 replies
NNuxt
Created by Rush on 11/13/2024 in #❓・help
Pinia problem
I have already tried to use pinia this way in several clean nuxt projects and I always had this problem
12 replies
NNuxt
Created by Rush on 11/13/2024 in #❓・help
Pinia problem
No, how can I do that?
12 replies
NNuxt
Created by Rush on 11/13/2024 in #❓・help
Pinia problem
that didn't help me
12 replies
NNuxt
Created by Rush on 7/25/2024 in #❓・help
Nuxt socket.io CORS error
this runs on port 8000 and frontend on port 3000 so i am allowing that origin
31 replies
NNuxt
Created by Rush on 7/25/2024 in #❓・help
Nuxt socket.io CORS error
import type { NitroApp } from "nitropack";
import { Server as Engine } from "engine.io";
import { Server } from "socket.io";
import { defineEventHandler } from "h3";
import { registerSocketHandlers } from "../sockets";
import { createServer } from "http";

export default defineNitroPlugin((nitroApp: NitroApp) => {
const engine = new Engine();

const httpServer = createServer();
const io = new Server(httpServer, {
cors: {
origin: "http://localhost:3000",
}
});

io.bind(engine);

registerSocketHandlers(io);

nitroApp.router.use("/socket.io/", defineEventHandler({
handler(event) {
engine.handleRequest(event.node.req, event.node.res);
event._handled = true;
},
websocket: {
open(peer) {
const nodeContext = peer.ctx.node;
const req = nodeContext.req;

// @ts-expect-error private method
engine.prepare(req);

const rawSocket = nodeContext.req.socket;
const websocket = nodeContext.ws;

// @ts-expect-error private method
engine.onWebSocket(req, rawSocket, websocket);
}
}
}));
});
import type { NitroApp } from "nitropack";
import { Server as Engine } from "engine.io";
import { Server } from "socket.io";
import { defineEventHandler } from "h3";
import { registerSocketHandlers } from "../sockets";
import { createServer } from "http";

export default defineNitroPlugin((nitroApp: NitroApp) => {
const engine = new Engine();

const httpServer = createServer();
const io = new Server(httpServer, {
cors: {
origin: "http://localhost:3000",
}
});

io.bind(engine);

registerSocketHandlers(io);

nitroApp.router.use("/socket.io/", defineEventHandler({
handler(event) {
engine.handleRequest(event.node.req, event.node.res);
event._handled = true;
},
websocket: {
open(peer) {
const nodeContext = peer.ctx.node;
const req = nodeContext.req;

// @ts-expect-error private method
engine.prepare(req);

const rawSocket = nodeContext.req.socket;
const websocket = nodeContext.ws;

// @ts-expect-error private method
engine.onWebSocket(req, rawSocket, websocket);
}
}
}));
});
is there something wrong?
31 replies
NNuxt
Created by Rush on 7/25/2024 in #❓・help
Nuxt socket.io CORS error
@Archerist I tried it on localhost with different ports and the error is same
31 replies
NNuxt
Created by Rush on 7/25/2024 in #❓・help
Nuxt socket.io CORS error
for what should i look there?
31 replies
NNuxt
Created by Rush on 7/25/2024 in #❓・help
Nuxt socket.io CORS error
its this error in console from origin 'http://localhost:3000/' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
31 replies
NNuxt
Created by Rush on 7/25/2024 in #❓・help
Nuxt socket.io CORS error
with configured cors origin in nuxt
31 replies
NNuxt
Created by Rush on 7/25/2024 in #❓・help
Nuxt socket.io CORS error
i mean that i get the cors origin error in console when trying to connect to websocket
31 replies
NNuxt
Created by Rush on 7/25/2024 in #❓・help
Nuxt socket.io CORS error
do i need to setup it somehow to allow nginx to forward the nuxt cors headers?
31 replies
NNuxt
Created by Rush on 7/25/2024 in #❓・help
Nuxt socket.io CORS error
nginx.conf:
server {
listen 80 default_server;
listen [::]:80 default_server;

server_name _;

deny all;
}

server {
listen 80;
listen [::]:80;

# cloudflare ips
allow 103.21.244.0/22;
allow 103.22.200.0/22;
allow 103.31.4.0/22;
allow 104.16.0.0/13;
allow 104.24.0.0/14;
allow 108.162.192.0/18;
allow 131.0.72.0/22;
allow 141.101.64.0/18;
allow 162.158.0.0/15;
allow 172.64.0.0/13;
allow 173.245.48.0/20;
allow 188.114.96.0/20;
allow 190.93.240.0/20;
allow 197.234.240.0/22;
allow 198.41.128.0/17;

server_name my-domain.com;

location / {
proxy_pass http://my-app-1:3000;

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Uri $request_uri;
proxy_set_header X-Forwarded-Host $host;
}
}
server {
listen 80 default_server;
listen [::]:80 default_server;

server_name _;

deny all;
}

server {
listen 80;
listen [::]:80;

# cloudflare ips
allow 103.21.244.0/22;
allow 103.22.200.0/22;
allow 103.31.4.0/22;
allow 104.16.0.0/13;
allow 104.24.0.0/14;
allow 108.162.192.0/18;
allow 131.0.72.0/22;
allow 141.101.64.0/18;
allow 162.158.0.0/15;
allow 172.64.0.0/13;
allow 173.245.48.0/20;
allow 188.114.96.0/20;
allow 190.93.240.0/20;
allow 197.234.240.0/22;
allow 198.41.128.0/17;

server_name my-domain.com;

location / {
proxy_pass http://my-app-1:3000;

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Uri $request_uri;
proxy_set_header X-Forwarded-Host $host;
}
}
31 replies
NNuxt
Created by Rush on 7/25/2024 in #❓・help
Nuxt socket.io CORS error
because nginx is blocking it
31 replies
NNuxt
Created by Rush on 7/25/2024 in #❓・help
Nuxt socket.io CORS error
if i set them in nuxt, it doesnt work
31 replies
NNuxt
Created by Rush on 7/25/2024 in #❓・help
Nuxt socket.io CORS error
But normally it would be necessary to configure the allowed origins in nuxt. Why doesn't it have to be done there if it is previously in nginx?
31 replies
NNuxt
Created by Rush on 7/25/2024 in #❓・help
Nuxt socket.io CORS error
i found that too, but it doesnt answer my question
31 replies
NNuxt
Created by Rush on 7/25/2024 in #❓・help
Nuxt socket.io CORS error
cors is needed if you want to access the server from a different address than the one where nuxt is running
31 replies
NNuxt
Created by Rush on 7/25/2024 in #❓・help
Nuxt socket.io CORS error
you must have set something up, although maybe not cors
31 replies