setup postgres backend

This commit is contained in:
Vomitblood 2024-11-11 00:43:09 +08:00
parent 1f1a667a02
commit 9bf78374b7
8 changed files with 79 additions and 3 deletions

14
README
View file

@ -14,3 +14,17 @@
10. sever side request forgery 10. sever side request forgery
11. broken authentication and session management 11. broken authentication and session management
12. clickjacking 12. clickjacking
## backend
backend-for-frontend server
!remember to set the environment variables
!include this in the setup instructions
!should we use a .env file and let the user set the variables?
PGHOST=localhost
PGPORT=5432
PGDATABASE=asdfdb
PGUSER=asdfuser
PGPASSWORD=asdfpassword

Binary file not shown.

View file

@ -18,8 +18,11 @@
"@mui/lab": "^6.0.0-beta.14", "@mui/lab": "^6.0.0-beta.14",
"@mui/material": "^6.1.6", "@mui/material": "^6.1.6",
"@tauri-apps/api": "^2.1.0", "@tauri-apps/api": "^2.1.0",
"@types/pg": "^8.11.10",
"dotenv": "^16.4.5",
"jotai": "^2.10.1", "jotai": "^2.10.1",
"next": "^15.0.3", "next": "^15.0.3",
"pg": "^8.13.1",
"react": "^18.3.1", "react": "^18.3.1",
"react-dom": "^18.3.1" "react-dom": "^18.3.1"
}, },

View file

@ -3,7 +3,6 @@ import {
Button, Button,
Container, Container,
Grid2, Grid2,
Input,
Switch, Switch,
TextField, TextField,
Typography, Typography,
@ -12,7 +11,6 @@ import {
import { HeaderBar } from "../HeaderBar/HeaderBar"; import { HeaderBar } from "../HeaderBar/HeaderBar";
import { AttackItem } from "../Home/AttackItem"; import { AttackItem } from "../Home/AttackItem";
import Link from "next/link";
export const Layout = () => { export const Layout = () => {
// contexts // contexts
@ -78,7 +76,11 @@ export const Layout = () => {
debounce when typing debounce when typing
update textfield color based on the response update textfield color based on the response
*/} */}
<TextField fullWidth label="Paste your backend URL here" /> <TextField
fullWidth
label="Paste your backend URL here"
value={process.env.PGHOST}
/>
</Box> </Box>
<Button href="https://github.com/cspj-nyp/cspj-application"> <Button href="https://github.com/cspj-nyp/cspj-application">
Need help getting started? Need help getting started?

View file

@ -2,6 +2,7 @@ import { Box, Stack } from "@mui/material";
import { WindowButtons } from "./WindowButtons"; import { WindowButtons } from "./WindowButtons";
import { NavigationButtons } from "./NavigationButtons"; import { NavigationButtons } from "./NavigationButtons";
import { RouteDisplay } from "./RouteDisplay"; import { RouteDisplay } from "./RouteDisplay";
import { Testing } from "../Testing/Testing";
export const HeaderBar = () => { export const HeaderBar = () => {
return ( return (
@ -70,6 +71,7 @@ export const HeaderBar = () => {
flexDirection: "row", flexDirection: "row",
}} }}
> >
<Testing />
<WindowButtons /> <WindowButtons />
</Stack> </Stack>
</Box> </Box>

View file

@ -0,0 +1,24 @@
import { useState } from "react";
import { FloatingDialog } from "../Generic/FloatingDialog";
import { Button } from "@mui/material";
export const Testing = () => {
// states
const [openState, setOpenState] = useState(false);
const [maximisedState, setMaximisedState] = useState(false);
// functions
const close = () => setOpenState(false);
return (
<FloatingDialog
body={<div>Test</div>}
close={close}
maximisedState={maximisedState}
openButton={<Button onClick={() => setOpenState(true)}>open</Button>}
openState={openState}
setMaximisedState={setMaximisedState}
title="Testing"
/>
);
};

View file

@ -0,0 +1,17 @@
import { Client } from "pg";
import "dotenv/config";
console.log("PGHOST:", process.env.PGHOST);
export const pgClient = new Client({
host: "localhost",
port: 5432,
user: "asdfuser",
password: "asdfpassword",
database: "asdfdb",
});
pgClient
.connect()
.then(() => console.log("Connected to PostgreSQL"))
.catch((err) => console.error("Error connecting to PostgreSQL", err));

14
docker/docker-compose.yml Normal file
View file

@ -0,0 +1,14 @@
services:
postgres:
image: postgres:latest
container_name: postgres_db
environment:
POSTGRES_USER: asdfuser
POSTGRES_PASSWORD: asdfpassword
POSTGRES_DB: asdfdb
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data: