-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
37 lines (31 loc) · 858 Bytes
/
app.js
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 mssql = require("mssql");
const app = express();
const PORT = process.env.PORT || 3000;
const config = {
user: "sa",
password: "saadmin",
server: "DESKTOP-89ACCK5",
database: "db_test",
options: {
encrypt: true,
trustServerCertificate: true, // Menonaktifkan pengecekan sertifikat
},
};
app.use(express.json());
// Route untuk mendapatkan data dari database
app.get('/api/data', async (req, res) => {
try {
// Buat koneksi ke SQL Server
const pool = await mssql.connect(config);
const result = await pool.request().query('Exec SP_Users');
res.json(result.recordset);
} catch (error) {
console.error(error);
res.status(500).send('Internal Server Error');
}
});
// Jalankan server
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});