database
This commit is contained in:
@ -9,6 +9,9 @@ const mainController = {
|
||||
},
|
||||
script: (req, res) => {
|
||||
res.sendFile(path.resolve(__dirname + '/../public/script.js'));
|
||||
},
|
||||
ecc: (req, res) => {
|
||||
res.sendFile(path.resolve(__dirname + '/../public/ecc.js'));
|
||||
}
|
||||
};
|
||||
|
||||
|
36
src/db.js
Normal file
36
src/db.js
Normal file
@ -0,0 +1,36 @@
|
||||
const { Client } = require('pg');
|
||||
|
||||
const dbConfig = {
|
||||
user: process.env.POSTGRES_USER || 'e2ee',
|
||||
password: process.env.POSTGRES_PASSWORD,
|
||||
host: process.env.POSTGRES_HOST || '127.0.0.1',
|
||||
port: process.env.POSTGRES_PORT || '5432',
|
||||
database: process.env.POSTGRES_DB || 'e2ee',
|
||||
};
|
||||
|
||||
const client = new Client(dbConfig);
|
||||
|
||||
const database = {
|
||||
init: () => {
|
||||
client.connect().then(() => {
|
||||
let querryString = `
|
||||
CREATE table user (
|
||||
uuid integer primary key,
|
||||
pubkey text
|
||||
);
|
||||
`
|
||||
client.query(querryString, (err, _) => {
|
||||
if (err) {
|
||||
console.error('Error executing query', err);
|
||||
}
|
||||
client.end().then(() => {}).catch((err) => {
|
||||
console.error('Error closing connection', err);
|
||||
});
|
||||
});
|
||||
}).catch((err) => {
|
||||
console.error('Error connecting to database ', err);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = database;
|
0
src/public/ecc.js
Normal file
0
src/public/ecc.js
Normal file
@ -6,7 +6,8 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="/style.css">
|
||||
<script src="/socket.io/socket.io.js" defer></script>
|
||||
<script src="script.js" defer></script>
|
||||
<script src="/script.js" defer></script>
|
||||
<script src="/ecc.js" defer></script>
|
||||
<!--load bootstrap-->
|
||||
<link rel="stylesheet" href="/css/bootstrap.min.css" />
|
||||
</head>
|
||||
|
@ -14,4 +14,8 @@ router
|
||||
.route("/script.js")
|
||||
.get(mainController.script);
|
||||
|
||||
router
|
||||
.route("/ecc.js")
|
||||
.get(mainController.ecc);
|
||||
|
||||
module.exports = router;
|
||||
|
Reference in New Issue
Block a user