-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
37 lines (30 loc) · 1.1 KB
/
Copy pathserver.js
File metadata and controls
37 lines (30 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const express = require("express");
const path = require("path");
const { execFile, exec } = require("child_process");
const app = express();
const PORT = process.env.PORT || 3000;
const C_SRC = path.join(__dirname, "password.c");
const BINARY = path.join(__dirname, "password");
exec(`gcc "${C_SRC}" -o "${BINARY}"`, (err, stdout, stderr) => {
if (err) {
console.error("Failed to compile password.c:", stderr);
process.exit(1);
}
console.log("password.c compiled successfully");
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "index.html"));
});
app.get("/generate", (req, res) => {
const length = req.query.length || "12";
execFile(BINARY, [length], (error, stdout, stderr) => {
if (error) {
console.error("Generator error:", stderr);
return res.status(500).json({ error: "Generator failed" });
}
res.json({ password: stdout.trim() });
});
});
app.listen(PORT, () => {
console.log(`PassForge running at http://localhost:${PORT}`);
});
});