Skip to content

Commit

Permalink
try connexion api interne au cluster avec middleware sur serveur express
Browse files Browse the repository at this point in the history
  • Loading branch information
Khagou committed Mar 23, 2024
1 parent 2ad13b5 commit 1fc3e7e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 32 deletions.
2 changes: 1 addition & 1 deletion client/src/components/Portfolio/PortfolioContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const PortfolioContent = () => {

useEffect(() => {
axios
.get(process.env.REACT_APP_URL_API + "/images")
.get("api/images")
.then((res) => setData(res.data));
}, []);

Expand Down
2 changes: 1 addition & 1 deletion client/src/components/home/Apropos.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Apropos = () => {
useEffect(() => {
console.log(process.env.REACT_APP_URL_API);
axios
.get(process.env.REACT_APP_URL_API + "/article")
.get("api/article")
.then((res) => setData(res.data));
}, []);
return (
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/home/Skills.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const Skills = () => {
// Le useEffect ce joue lorsque le composant est monté
useEffect(() => {
axios
.get(process.env.REACT_APP_URL_API + "/tech") // url de l'api
.get("api/tech") // url de l'api
.then((res) => setData(res.data))
.catch((error) => console.error(error));
}, []);
Expand Down
7 changes: 7 additions & 0 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const express = require("express");
const { createProxyMiddleware } = require('http-proxy-middleware');

require("dotenv").config({ path: "./config/.env" });
const app = express();
Expand All @@ -19,6 +20,12 @@ const MAIL_PASS = process.env.MAIL_PASS;
app.use(bodyParser.json());
app.use(express.static("client/build"));
app.use(cors());

app.use('/api', createProxyMiddleware({
target: 'http://back-service.default.svc.cluster.local:7000',
changeOrigin: true,
}));

app.use("/api/tech", techRoutes);
app.use("/api/images", imagesRoutes);
app.use("/api/article", articleRoutes);
Expand Down
29 changes: 0 additions & 29 deletions server/prod-back.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,4 @@ spec:
ports:
- port: 7000
targetPort: 7000
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: khagu-dev-back-ingress
annotations:
kubernetes.io/ingress.class: "gce"
spec:
rules:
- host: api.projet.khagu-dev.fr
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: back-service
port:
number: 7000
- host: www.api.projet.khagu-dev.fr
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: back-service
port:
number: 7000
---

0 comments on commit 1fc3e7e

Please sign in to comment.