Spaces:
Runtime error
Runtime error
Download dist/server.js from sardarbipul/work-Update: direct link, hf CLI and curl.
- Browser
- Download file 2.57 kB
-
https://huggingface.co/spaces/sardarbipul/work-Update/resolve/main/dist/server.js
- Command line
-
hf download hf://spaces/sardarbipul/work-Update/dist/server.js
-
curl -L -o server.js https://huggingface.co/spaces/sardarbipul/work-Update/resolve/main/dist/server.js
2.57 kB
| ; | |
| var __importDefault = (this && this.__importDefault) || function (mod) { | |
| return (mod && mod.__esModule) ? mod : { "default": mod }; | |
| }; | |
| Object.defineProperty(exports, "__esModule", { value: true }); | |
| const express_1 = __importDefault(require("express")); | |
| const pg_1 = require("pg"); | |
| const fs_1 = __importDefault(require("fs")); | |
| const path_1 = __importDefault(require("path")); | |
| const app = (0, express_1.default)(); | |
| const port = 3000; | |
| app.use(express_1.default.json()); | |
| app.use(express_1.default.static("public")); | |
| let caCert; | |
| try { | |
| caCert = fs_1.default.readFileSync(path_1.default.join(__dirname, "ca.pem"), "utf8"); | |
| console.log("CA certificate loaded successfully."); | |
| } | |
| catch (error) { | |
| console.error("Failed to load CA certificate:", error.message); | |
| process.exit(1); | |
| } | |
| const pool = new pg_1.Pool({ | |
| connectionString: "postgres://avnadmin:AVNS_BsUJEz_hcswptIqk5yR@postgres-bs-bebb.l.aivencloud.com:21759/defaultdb", | |
| ssl: { | |
| ca: caCert, | |
| rejectUnauthorized: true, | |
| checkServerIdentity: () => undefined, | |
| }, | |
| }); | |
| pool.connect((err, client, release) => { | |
| if (err) { | |
| console.error("Database connection error:", err.message); | |
| process.exit(1); | |
| } | |
| console.log("Successfully connected to PostgreSQL database."); | |
| release(); | |
| }); | |
| app.post("/save", async (req, res) => { | |
| const { date, technology, entries } = req.body; | |
| const client = await pool.connect(); | |
| try { | |
| await client.query("BEGIN"); | |
| for (const entry of entries) { | |
| await client.query("INSERT INTO daily_reports (report_date, technology, sl_no, work_completed, from_time, to_time) VALUES ($1, $2, $3, $4, $5, $6)", [ | |
| date, | |
| technology, | |
| entry.sl_no, | |
| entry.work_completed, | |
| entry.from_time, | |
| entry.to_time, | |
| ]); | |
| } | |
| await client.query("COMMIT"); | |
| res.json({ success: true }); | |
| } | |
| catch (error) { | |
| await client.query("ROLLBACK"); | |
| res.status(500).json({ error: error.message }); | |
| } | |
| finally { | |
| client.release(); | |
| } | |
| }); | |
| app.get("/fetch", async (req, res) => { | |
| const { date } = req.query; | |
| try { | |
| const result = await pool.query("SELECT * FROM daily_reports WHERE report_date = $1 ORDER BY sl_no ASC", [date]); | |
| res.json(result.rows); | |
| } | |
| catch (error) { | |
| res.status(500).json({ error: error.message }); | |
| } | |
| }); | |
| app.listen(port, () => { | |
| console.log(`Server running on http://localhost:${port}`); | |
| }); | |