feature: 🎂 production mode

This commit is contained in:
Sammwy 2025-01-26 18:45:22 -03:00
parent 0e27a8b54c
commit 26f6a37e80
No known key found for this signature in database
GPG key ID: E6B924CEF399DE44
6 changed files with 141 additions and 35 deletions

49
Gruntfile.cjs Normal file
View file

@ -0,0 +1,49 @@
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
// Build from source.
shell: {
clean: {
command: "rimraf dist",
},
buildClient: {
command: "vite build",
},
buildServer: {
command:
"tsc --project tsconfig.server.json && tsc-alias -p tsconfig.server.json",
},
},
// Copy worker files (Backend attack methods)
copy: {
static: {
expand: true,
cwd: "server/workers/",
src: "*",
dest: "dist/workers/",
},
},
// Run concurrent tasks
concurrent: {
build: ["shell:buildClient", "shell:buildServer"],
},
});
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-shell");
grunt.loadNpmTasks("grunt-concurrent");
// Run our tasks
grunt.registerTask("build", [
"shell:clean",
"concurrent:build",
"copy:static",
]);
grunt.registerTask("build_server", ["shell:buildServer"]);
grunt.registerTask("build_client", ["shell:buildClient"]);
};

BIN
bun.lockb

Binary file not shown.

View file

@ -3,26 +3,30 @@
"private": true,
"version": "0.0.0",
"type": "module",
"main": "./dist/index.js",
"scripts": {
"dev": "concurrently --ks SIGKILL -n \"Client,Server\" \"npm run dev:client\" \"npm run dev:server\"",
"dev:server": "tsx watch server/",
"dev:client": "vite",
"build": "vite build",
"dev:server": "cross-env NODE_ENV=development tsx watch server/",
"dev:client": "cross-env NODE_ENV=development vite",
"clean": "rimraf ./dist",
"build": "grunt build",
"build:client": "grunt build_client",
"build:server": "grunt build_server",
"lint": "eslint .",
"preview": "vite preview"
"preview": "vite preview",
"start": "cross-env NODE_ENV=production node ."
},
"dependencies": {
"axios": "^1.7.9",
"body-parser": "^1.20.3",
"concurrently": "^9.1.2",
"cross-env": "^7.0.3",
"express": "^4.21.2",
"lucide-react": "^0.344.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"socket.io": "^4.7.4",
"socket.io-client": "^4.7.4",
"socks-proxy-agent": "^8.0.5",
"tsx": "^4.19.2"
"socks-proxy-agent": "^8.0.5"
},
"devDependencies": {
"@eslint/js": "^9.9.1",
@ -31,12 +35,20 @@
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"autoprefixer": "^10.4.18",
"concurrently": "^9.1.2",
"eslint": "^9.9.1",
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
"eslint-plugin-react-refresh": "^0.4.11",
"globals": "^15.9.0",
"grunt": "^1.6.1",
"grunt-concurrent": "^3.0.0",
"grunt-contrib-copy": "^1.0.0",
"grunt-shell": "^4.0.0",
"postcss": "^8.4.35",
"rimraf": "^6.0.1",
"tailwindcss": "^3.4.1",
"tsc-alias": "^1.8.10",
"tsx": "^4.19.2",
"typescript": "^5.5.3",
"typescript-eslint": "^8.3.0",
"vite": "^5.4.2"

View file

@ -1,15 +1,15 @@
import express from "express";
import { readFileSync, writeFileSync } from "fs";
import { createServer } from "http";
import { dirname, join } from "path";
import { readFileSync, writeFileSync } from "fs";
import { Server } from "socket.io";
import { fileURLToPath } from "url";
import { Worker } from "worker_threads";
import bodyParser from "body-parser";
import { currentPath, loadProxies, loadUserAgents } from "./fileLoader";
import { AttackMethod } from "./lib";
import { filterProxies } from "./proxyUtils";
import bodyParser from "body-parser";
// Define the workers based on attack type
const attackWorkers: { [key in AttackMethod]: string } = {
@ -21,14 +21,15 @@ const attackWorkers: { [key in AttackMethod]: string } = {
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const __prod = process.env.NODE_ENV === "production";
const app = express();
const httpServer = createServer(app);
const io = new Server(httpServer, {
cors: {
origin: "http://localhost:5173",
origin: __prod ? "" : "http://localhost:5173",
methods: ["GET", "POST"],
allowedHeaders: ["Content-Type"]
allowedHeaders: ["Content-Type"],
},
});
@ -38,6 +39,8 @@ const userAgents = loadUserAgents();
console.log("Proxies loaded:", proxies.length);
console.log("User agents loaded:", userAgents.length);
app.use(express.static(join(__dirname, "public")));
io.on("connection", (socket) => {
console.log("Client connected");
@ -109,47 +112,56 @@ io.on("connection", (socket) => {
});
app.get("/configuration", (req, res) => {
res.setHeader("Access-Control-Allow-Origin", "http://localhost:5173")
res.setHeader("Access-Control-Allow-Origin", "http://localhost:5173");
res.setHeader("Content-Type", "application/json");
let proxiesText = readFileSync(join(currentPath(), "data", "proxies.txt"), "utf-8");
let uasText = readFileSync(join(currentPath(), "data", "uas.txt"), "utf-8");
const proxiesText = readFileSync(
join(currentPath(), "data", "proxies.txt"),
"utf-8"
);
const uasText = readFileSync(join(currentPath(), "data", "uas.txt"), "utf-8");
res.send({
proxies: btoa(proxiesText),
uas: btoa(uasText),
})
})
});
});
app.options('/configuration', (req, res) => {
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:5173');
res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
app.options("/configuration", (req, res) => {
res.setHeader("Access-Control-Allow-Origin", "http://localhost:5173");
res.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
res.send();
});
app.post("/configuration", bodyParser.json(), (req, res) => {
res.setHeader("Access-Control-Allow-Methods", "POST");
res.setHeader("Access-Control-Allow-Headers", "Content-Type")
res.setHeader("Access-Control-Allow-Origin", "http://localhost:5173")
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
res.setHeader("Access-Control-Allow-Origin", "http://localhost:5173");
res.setHeader("Content-Type", "application/text");
// console.log(req.body)
// atob and btoa are used to avoid the problems in sending data with // characters, etc.
let proxies = atob(req.body["proxies"]);
let uas = atob(req.body["uas"]);
const proxies = atob(req.body["proxies"]);
const uas = atob(req.body["uas"]);
writeFileSync(join(currentPath(), "data", "proxies.txt"), proxies, {
encoding: "utf-8"
encoding: "utf-8",
});
writeFileSync(join(currentPath(), "data", "uas.txt"), uas, {
encoding: "utf-8"
encoding: "utf-8",
});
res.send("OK")
})
const PORT = 3000;
httpServer.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
res.send("OK");
});
const PORT = parseInt(process.env.PORT || "3000");
httpServer.listen(PORT, () => {
if (__prod) {
console.log(
`(Production Mode) Client and server is running under http://localhost:${PORT}`
);
} else {
console.log(`Server is running under development port ${PORT}`);
}
});

29
tsconfig.server.json Normal file
View file

@ -0,0 +1,29 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"*": ["*"]
},
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "node",
"strict": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"outDir": "dist",
"rootDir": "server",
"allowSyntheticDefaultImports": true,
"noImplicitAny": false
},
"include": ["server/**/*.ts"],
"exclude": ["node_modules"],
"tsc-alias": {
"verbose": false,
"resolveFullPaths": true,
"fileExtensions": {
"inputGlob": "{js,jsx,mjs}",
"outputCheck": ["js", "json", "jsx", "mjs"]
}
}
}

View file

@ -1,5 +1,6 @@
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import react from "@vitejs/plugin-react";
import path from "path";
import { defineConfig } from "vite";
// https://vitejs.dev/config/
export default defineConfig({
@ -7,4 +8,7 @@ export default defineConfig({
optimizeDeps: {
exclude: [],
},
build: {
outDir: path.resolve(__dirname, "dist/public"),
},
});