This commit is contained in:
slawk0
2024-08-19 19:50:06 +02:00
commit 229a9f5b18
4 changed files with 96 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
node_modules/
.idea
package-lock.json
.env

48
index.js Normal file
View File

@@ -0,0 +1,48 @@
const pg = require('pg');
const express = require('express');
const session = require('express-session');
const path = require('path');
const {Client} = require('pg');
const port = 3000
const app = express()
require('dotenv').config()
const main = async () => {
const client = new Client({
user: process.env.PG_USER,
password: process.env.PG_PASSWORD,
database: process.env.PG_DATABASE,
host: process.env.PG_HOST,
});
await client.connect();
try {
console.log(await client.query('SELECT 1'));
} finally {
await client.end();
}
};
main().catch(console.error);
app.get('/', (req, res) => {
const main = async () => {
const client = new Client({
user: process.env.PG_USER,
password: process.env.PG_PASSWORD,
database: process.env.PG_DATABASE,
host: process.env.PG_HOST,
});
await client.connect();
try {
console.log(await client.query('SELECT 1'));
} finally {
await client.end();
}
};
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})

28
login.html Normal file
View File

@@ -0,0 +1,28 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div class="login">
<h1>Login</h1>
<form action="/auth" method="post">
<label for="username">
<i class="fas fa-user"></i>
</label>
<input type="text" name="username" placeholder="Username" id="username" required>
<label for="password">
<i class="fas fa-lock"></i>
</label>
<input type="password" name="password" placeholder="Password" id="password" required>
<input type="submit" value="Login">
</form>
</div>
</body>
</html>

16
package.json Normal file
View File

@@ -0,0 +1,16 @@
{
"name": "web-chat",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"private": true,
"dependencies": {
"dotenv": "^16.4.5",
"express": "^4.19.2",
"express-session": "^1.18.0",
"pg": "^8.12.0"
}
}