database
This commit is contained in:
parent
ba13626d46
commit
4abe5a07f2
6
Makefile
6
Makefile
@ -1,10 +1,12 @@
|
||||
|
||||
run: clean build
|
||||
podman run --replace -dt -p 3333:3333 --name=e2ee e2ee-messaging-service:latest
|
||||
podman pod create --name=e2ee -p 3333:3333
|
||||
podman run -d --pod=e2ee -e POSTGRES_PASSWORD="password" -e POSTGRES_DB="e2ee" -e POSTGRES_USER="e2ee" -e POSTGRES_INITDB_ARGS="--encoding=UTF-8 --lc-collate=C --lc-ctype=C" --name=e2ee-db docker.io/library/postgres:15
|
||||
podman run -d --pod=e2ee --name=e2ee-app e2ee-messaging-service:latest
|
||||
build:
|
||||
podman build -t e2ee-messaging-service .
|
||||
test:
|
||||
curl http://localhost:3333
|
||||
podman logs e2ee
|
||||
clean:
|
||||
podman rm -f e2ee
|
||||
podman pod rm -f e2ee
|
||||
|
@ -12,6 +12,7 @@
|
||||
"bootstrap": "^5.3.3",
|
||||
"cookie-parser": "^1.4.7",
|
||||
"express": "^4.21.2",
|
||||
"pg": "^8.13.1",
|
||||
"socket.io": "^4.8.1"
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user