Skip to content

Commit

Permalink
add axios and cors
Browse files Browse the repository at this point in the history
  • Loading branch information
YehiaFarghaly committed Oct 7, 2023
1 parent 97d0028 commit 237dbfd
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 16 deletions.
21 changes: 21 additions & 0 deletions client/src/utils/AxiosConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import axios from 'axios';

// Define the base URLs for each microservice
const clinicBaseUrl = 'http://localhost:8001';
const patientBaseUrl = 'http://localhost:8002';
const pharmacyBaseUrl = 'http://localhost:8003';

export const clinicAxios = axios.create({
baseURL: clinicBaseUrl,
withCredentials: true,
});

export const patientAxios = axios.create({
baseURL: patientBaseUrl,
withCredentials: true,
});

export const pharmacyAxios = axios.create({
baseURL: pharmacyBaseUrl,
withCredentials: true,
});
26 changes: 23 additions & 3 deletions clinic/package-lock.json

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

1 change: 1 addition & 0 deletions clinic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"dependencies": {
"axios": "^1.5.1",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"mongoose": "^7.5.3",
Expand Down
7 changes: 6 additions & 1 deletion clinic/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import mongoose from 'mongoose';
import dotenv from 'dotenv';
import { healthPackage } from './api/HealthPackageAPI.js';
import { PORT } from './utils/Constants.js';
import cors from 'cors';
//import {doctor } from './api/doctor.js';
//import {appointment } from './api/appointment.js';
//import {admin } from './api/admin.js';
Expand All @@ -18,13 +19,17 @@ const connect = async () => {
await mongoose.connect(mongoURL);
console.log('Database connected');
} catch (err) {
console.error('Error connecting to the database:', err);
console.error('Error connecting to the database:', err);
}
};

await connect();

app.use(express.json());
app.use(cors({
origin: ["http://localhost:3000","http://localhost:3001", "http://localhost:3002"],
credentials: true
}))

healthPackage(app);
//admin(app);
Expand Down
26 changes: 23 additions & 3 deletions patient/package-lock.json

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

1 change: 1 addition & 0 deletions patient/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"mongoose": "^7.5.3",
Expand Down
23 changes: 14 additions & 9 deletions patient/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import mongoose from 'mongoose';
import dotenv from 'dotenv';
import { patient } from './api/patient.js';
import { PORT_NUMBER } from './utils/Constants.js';
import cors from 'cors';

dotenv.config();
const app = express();
Expand All @@ -11,21 +12,25 @@ const mongoURL = process.env.MONGO_URI;

const connect = async () => {
try {
await mongoose.connect( mongoURL );
console.log( 'Database connected' );
} catch ( err ) {
console.error( 'Error connecting to the database:', err );
await mongoose.connect(mongoURL);
console.log('Database connected');
} catch (err) {
console.error('Error connecting to the database:', err);
}
};

await connect();

app.use( express.json() );
app.use(express.json());
app.use(cors({
origin: ["http://localhost:3000","http://localhost:3001", "http://localhost:3002"],
credentials: true
}))

patient( app );
patient(app);

const port = process.env.PORT || PORT_NUMBER;

app.listen( port, () => {
console.log( `Server is running on port ${port}` );
} );
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});

0 comments on commit 237dbfd

Please sign in to comment.