bᥲkᥙg᥆
bᥲkᥙg᥆
Explore posts from servers
CDCloudflare Developers
Created by bᥲkᥙg᥆ on 6/7/2024 in #workers-help
websocket forward proxy server
i am trying to set up a custom WebSocket server. This server will act as an intermediary, forwarding all messages it receives to another WebSocket server
async function websocket(url, final) {
let resp = await fetch(url, {
headers: {
Upgrade: 'websocket',
"NDCDEVICEID": await getDeviceId(),
"NDC-MSG-SIG": await getSignature(final)
},
});

console.log(resp);

let ws = resp.webSocket;
if (!ws) {
throw new Error("server didn't accept WebSocket");
}

ws.accept();


}

export default {
async fetch(request, env, ctx) {
const upgradeHeader = request.headers.get('Upgrade');
if (upgradeHeader && upgradeHeader.toLowerCase() === 'websocket') {
const [client, server] = Object.values(new WebSocketPair());
const device_id = await getDeviceId();
const timestamp = new Date().getTime();
const final = `${device_id}|${timestamp}`;
const url = `http://ws1.aminoapps.com/?signbody=${final.replace('|', '%7C')}`;

console.log(url);

websocket(url, final);

server.accept();
server.addEventListener('message', async (event) => {

console.log('Client:', event.data);

server.send(`Echo: ${event.data}`);
});

return new Response(null, {
status: 101,
webSocket: server
});
}
async function websocket(url, final) {
let resp = await fetch(url, {
headers: {
Upgrade: 'websocket',
"NDCDEVICEID": await getDeviceId(),
"NDC-MSG-SIG": await getSignature(final)
},
});

console.log(resp);

let ws = resp.webSocket;
if (!ws) {
throw new Error("server didn't accept WebSocket");
}

ws.accept();


}

export default {
async fetch(request, env, ctx) {
const upgradeHeader = request.headers.get('Upgrade');
if (upgradeHeader && upgradeHeader.toLowerCase() === 'websocket') {
const [client, server] = Object.values(new WebSocketPair());
const device_id = await getDeviceId();
const timestamp = new Date().getTime();
const final = `${device_id}|${timestamp}`;
const url = `http://ws1.aminoapps.com/?signbody=${final.replace('|', '%7C')}`;

console.log(url);

websocket(url, final);

server.accept();
server.addEventListener('message', async (event) => {

console.log('Client:', event.data);

server.send(`Echo: ${event.data}`);
});

return new Response(null, {
status: 101,
webSocket: server
});
}
i am still new to cloudflare worker so let me know where i am wrong
1 replies
CC#
Created by bᥲkᥙg᥆ on 4/19/2024 in #help
excel modification
No description
113 replies
CC#
Created by bᥲkᥙg᥆ on 4/17/2024 in #help
Excel modify
No description
175 replies
CDCloudflare Developers
Created by bᥲkᥙg᥆ on 11/30/2023 in #general-help
chat history
async function run(model, prompt) {
const messages = [
{ role: 'system', content: 'You are a friendly assistant' },
{ role: 'user', content: prompt }
];

const response = await fetch(
`https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/run/${model}`,
{
headers: { Authorization: "Bearer {API_TOKEN}" },
method: "POST",
body: JSON.stringify({ messages }),
}
);
const result = await response.json();
return result;
}

run('@cf/meta/llama-2-7b-chat-int8', 'Tell me a story').then((response) => {
console.log(JSON.stringify(response));
});
async function run(model, prompt) {
const messages = [
{ role: 'system', content: 'You are a friendly assistant' },
{ role: 'user', content: prompt }
];

const response = await fetch(
`https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/run/${model}`,
{
headers: { Authorization: "Bearer {API_TOKEN}" },
method: "POST",
body: JSON.stringify({ messages }),
}
);
const result = await response.json();
return result;
}

run('@cf/meta/llama-2-7b-chat-int8', 'Tell me a story').then((response) => {
console.log(JSON.stringify(response));
});
can we make it remember our chat history? i tried appending user in messages but did not work
1 replies
CDCloudflare Developers
Created by bᥲkᥙg᥆ on 10/28/2023 in #workers-help
websocket headers
can we use custom headers in websocket worker
1 replies
CDCloudflare Developers
Created by bᥲkᥙg᥆ on 9/30/2023 in #general-help
Websocket issue
i successfully set up a forward WebSocket proxy server within a worker, and initially, it was functioning flawlessly on Heroku. However, recently, it has stopped receiving data from the WebSocket, although it continues to work perfectly on my local Pc
1 replies
CDCloudflare Developers
Created by bᥲkᥙg᥆ on 9/29/2023 in #workers-help
websocket server
i successfully set up a forward WebSocket proxy server within a worker, and initially, it was functioning flawlessly on Heroku. However, recently, it has stopped receiving data from the WebSocket, although it continues to work perfectly on my local Pc
1 replies
CDCloudflare Developers
Created by bᥲkᥙg᥆ on 8/19/2023 in #general-help
use cloudflare as vpn
can we use cloudflare as vpn ? i tried using cloudflare warp in my window vps but it's not opening is there any other method to use cloudflare as vpn or as a proxy in python terminal
5 replies
CDCloudflare Developers
Created by bᥲkᥙg᥆ on 8/1/2023 in #workers-help
forge.js availability
is forge.js is available in worker?
9 replies
CDCloudflare Developers
Created by bᥲkᥙg᥆ on 7/31/2023 in #workers-help
worker crypto
i wast trying to implement api to in cloudflare worker to generate deviceId but my function uses crypto library and i don't find the same function in cloudflare crypto:
using nodejs crypto lib.

function getDeviceI() {
let id = crypto.randomBytes(20).toString("binary");
let hmac = crypto.createHmac(
"sha1",
Buffer.from(
"E7309ECC0953C6FA60005B2765F99DBBC965C8E9",
"hex"
)
);
hmac.update(Buffer.from(Buffer.from("19", "hex") + id, "binary"));
return "19" + Buffer.from(id, "binary").toString("hex") + hmac.digest("hex");
}
correct deviceId:19CEB4EB9340402020E054720BEBAF280A8CEA373CC6E00629C9CEB1B3CB14FD5ABC0D4F5896DBAD4E
using nodejs crypto lib.

function getDeviceI() {
let id = crypto.randomBytes(20).toString("binary");
let hmac = crypto.createHmac(
"sha1",
Buffer.from(
"E7309ECC0953C6FA60005B2765F99DBBC965C8E9",
"hex"
)
);
hmac.update(Buffer.from(Buffer.from("19", "hex") + id, "binary"));
return "19" + Buffer.from(id, "binary").toString("hex") + hmac.digest("hex");
}
correct deviceId:19CEB4EB9340402020E054720BEBAF280A8CEA373CC6E00629C9CEB1B3CB14FD5ABC0D4F5896DBAD4E
can anyone help
7 replies