Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
fix remote database connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammedal-abdulhamid authored and Mohammedal-abdulhamid committed Feb 8, 2024
1 parent 5e3358b commit 5d240dd
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 23 deletions.
15 changes: 13 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^16.3.2",
"loading": "^1.13.3",
"loading.js": "^0.1.1",
Expand All @@ -24,14 +25,14 @@
"eject": "react-scripts eject",
"prod": "npm run build && npm run deploy",
"watch": "npm-watch",
"deploy": "aws s3 sync build/ s3://cyfhotelapp"
"deploy": "aws s3 sync build/ s3://cyfhotelapp",
"dev": " nodemon ./src/backend/server.js"
},
"devDependencies": {
"react-scripts": "^5.0.1",
"husky": "^8.0.3",
"prettier": "^2.8.4",
"pretty-quick": "^3.1.3"

"pretty-quick": "^3.1.3",
"react-scripts": "^5.0.1"
},
"husky": {
"hooks": {
Expand Down
2 changes: 1 addition & 1 deletion src/Bookings.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const Bookings = () => {
useEffect(() => {
const fetchData = async () => {
try {
const response = await fetch('https://temporary-cyf-react.onrender.com/');
const response = await fetch('http://18.171.60.156/api/data');
if (!response.ok) {
throw new Error("SERVER RESPONSE ERROR !!!");
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/db/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const dbConfig = {
password: process.env.POSTGRES_PASSWORD,
port: process.env.POSTGRES_PORT,
};

console.log(dbConfig)
const pool = new Pool(dbConfig);

pool.on('error', (err) => {
Expand Down
6 changes: 4 additions & 2 deletions src/backend/db/cyf_hotel.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
DROP DATABASE IF EXISTS cyfhotelapp;
CREATE DATABASE cyfhotelapp;
DROP DATABASE IF EXISTS cyf_hotel ;
CREATE DATABASE cyf_hotel ;

-- cyfhotelapp
4 changes: 3 additions & 1 deletion src/backend/db/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ function seed() {
.then(() => {
return insertBookingsData();
})
.catch((error) => console.error("Error seeding database:", error));
}

}



function createBookingsTable() {
Expand Down
21 changes: 9 additions & 12 deletions src/backend/server.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
const express = require('express');
const { Pool } = require('pg');
const path = require('path');
// const connection = require("./data/connection");
require('dotenv').config();
const path = require('path');
const pool = require("./db/connection");
const cors = require("cors")



const pool = new Pool({
user: process.env.POSTGRES_USER,
host: process.env.POSTGRES_HOST,
database: process.env.POSTGRES_DB,
password: process.env.POSTGRES_PASSWORD,
port: process.env.POSTGRES_PORT,
});

const app = express();
app.use(cors())
const Port = process.env.PORT || 4000;

app.use(express.static(path.join(__dirname, 'build')));
// app.use(express.static(path.join(__dirname, 'build')));

app.get('/api/data', async (req, res) => {
try {
Expand All @@ -32,9 +27,11 @@ app.get('/api/data', async (req, res) => {
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.get('/', (req, res) => {
res.send('Hello, World!');
});

app.listen(Port, () => {
console.log(`Server is running on port ${Port}`);
console.log(`Server is running on port ${Port}`);
console.log(`Database user: ${process.env.POSTGRES_USER}`);
});

0 comments on commit 5d240dd

Please sign in to comment.