Skip to content

Commit

Permalink
Fix header limit bug
Browse files Browse the repository at this point in the history
  • Loading branch information
codergautam committed Nov 1, 2024
1 parent 20ef993 commit 98ead83
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
21 changes: 21 additions & 0 deletions components/auth/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@ export function signOut() {
if(window.dontReconnect) {
return;
}

// remove all cookies
console.log("Removing cookies");
(function () {
var cookies = document.cookie.split("; ");
for (var c = 0; c < cookies.length; c++) {
var d = window.location.hostname.split(".");
while (d.length > 0) {
var cookieBase = encodeURIComponent(cookies[c].split(";")[0].split("=")[0]) + '=; expires=Thu, 01-Jan-1970 00:00:01 GMT; domain=' + d.join('.') + ' ;path=';
var p = location.pathname.split('/');
document.cookie = cookieBase + '/';
while (p.length > 0) {
document.cookie = cookieBase + p.join('/');
console.log(cookieBase + p.join('/'));
p.pop();
};
d.shift();
}
}
})();

window.location.reload();
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"private": true,
"type": "module",
"scripts": {
"dev": "node welcome.js && npx concurrently \"cross-env nodemon ws/ws --exec \"node --no-warnings=ExperimentalWarning\" --watch ws/ws.js\" \"cross-env nodemon server.js --exec \"node --no-warnings=ExperimentalWarning\" --watch server.js\" \"npx next dev\"",
"dev": "node welcome.js && npx concurrently \"cross-env UWS_HTTP_MAX_HEADERS_SIZE=16384 nodemon ws/ws --exec \"node --no-warnings=ExperimentalWarning\" --watch ws/ws.js\" \"cross-env nodemon server.js --exec \"node --no-warnings=ExperimentalWarning\" --watch server.js\" \"npx next dev\"",
"build": "cross-env next build",
"start-api": "cross-env NODE_ENV=production node server.js",
"start-ws": "cross-env NODE_ENV=production node ws/ws",
"start-ws": "cross-env UWS_HTTP_MAX_HEADERS_SIZE=16384 NODE_ENV=production node ws/ws",
"heroku-postbuild": "cross-env next build"
},
"dependencies": {
Expand Down
2 changes: 2 additions & 0 deletions styles/globals.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ button {
overflow-y: auto;
}

/// ccar

.home__content.hidden {
left: 100%;
opacity: 0;
Expand Down
26 changes: 14 additions & 12 deletions ws/ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ import { players, games } from '../serverUtils/states.js';
import Memsave from '../models/Memsave.js';
import blockedAt from 'blocked-at';

import axios from 'axios';

config();

// Load the profanity filter
const filter = new Filter();
filter.removeWords('damn')
Expand Down Expand Up @@ -198,26 +195,31 @@ process.on('unhandledRejection', (reason, promise) => {
stop('unhandledRejection');
});
// uWebSockets.js
let app = uws.App();
let app = uws.App({

});
app.listen('0.0.0.0', port, (ws) => {
if (ws) {
log('**WS Server started on port** ' + port);
}
});

app.get('/', (res, req) => {
// make sureonly cf can access
let ip = req.getHeader('cf-connecting-ip') || res.getRemoteAddressAsText();
// cjeck if ip isarraybuffer
if (ip instanceof ArrayBuffer) {
ip = new TextDecoder().decode(ip);
}

// count all the headers
let headerKb = 0;
req.forEach((key, value) => {

headerKb += key.length + value.length;

});
headerKb = headerKb / 1024;


setCorsHeaders(res);
res.writeHeader('Content-Type', 'text/plain');
res.writeHeader('Content-Type', 'text/html');
res.writeStatus('200 OK');
res.end("WorldGuessr - Powered by uWebSockets.js");
res.end("WorldGuessr - Powered by uWebSockets.js<br>Headers: "+headerKb.toFixed(2)+'kb');
});

// maintenance mode
Expand Down

0 comments on commit 98ead83

Please sign in to comment.