Skip to content

Commit

Permalink
post put delete added
Browse files Browse the repository at this point in the history
  • Loading branch information
Piootrekk committed Dec 28, 2023
1 parent 05703a8 commit f0d386e
Show file tree
Hide file tree
Showing 3 changed files with 1,240 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
node_modules/
dist/

package-lock.json

*.log
*.gz
*.log
Expand Down
125 changes: 119 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,76 @@ app.use((req, res, next) => {
});

app.get("/", (req, res) => {
res.send("Just a simple proxy server.");
res.send(
`Just a simple proxy server.
Use: /getNormal /getEncode /postNormal /postEncode /putNormal /putEncode /deleteNormal /deleteEncode`
);
});

app.get("/getEncode/:path", async (req, res) => {
console.log("Received request to /getTest with path:", req.params.path);
console.log("Received request to /getEncode with path:", req.params.path);

const response = await axios.get(req.params.path);
res.json(response.data);
try {
const response = await axios.get(req.params.path);
res.json(response.data);
} catch (error) {
console.error("Error in /getEncode endpoint:", error);
res.status(500).json({
error: "An error occurred while processing the API request.",
path: req.params.path,
});
}
});

app.post("/postEncode/:path", async (req, res) => {
console.log(
"Received POST request to /postEncode with path:",
req.params.path
);

try {
const response = await axios.post(req.params.path, req.body);
res.json(response.data);
} catch (error) {
console.error("Error in /postEncode endpoint:", error);
res.status(500).json({
error: "An error occurred while processing the API request.",
path: req.params.path,
});
}
});

app.put("/putEncode/:path", async (req, res) => {
console.log("Received PUT request to /putEncode with path:", req.params.path);

try {
const response = await axios.put(req.params.path, req.body);
res.json(response.data);
} catch (error) {
console.error("Error in /putEncode endpoint:", error);
res.status(500).json({
error: "An error occurred while processing the API request.",
path: req.params.path,
});
}
});

app.delete("/deleteEncode/:path", async (req, res) => {
console.log(
"Received DELETE request to /deleteEncode with path:",
req.params.path
);

try {
const response = await axios.delete(req.params.path);
res.json(response.data);
} catch (error) {
console.error("Error in /deleteEncode endpoint:", error);
res.status(500).json({
error: "An error occurred while processing the API request.",
path: req.params.path,
});
}
});

app.get("/getNormal/:path(*)", async (req, res) => {
Expand All @@ -35,8 +97,59 @@ app.get("/getNormal/:path(*)", async (req, res) => {
} catch (error) {
console.error("Error in /getNormal endpoint:", error);
res.status(500).json({
error: "Wystąpił błąd podczas przetwarzania zapytania API.",
parm: req.params.path,
error: "An error occurred while processing the API request.",
path: req.params.path,
});
}
});

app.post("/postNormal/:path(*)", async (req, res) => {
try {
const decodedPath = decodeURIComponent(req.params.path);
console.log("Received POST request to /postNormal with path:", decodedPath);

const response = await axios.post(decodedPath, req.body);
res.json(response.data);
} catch (error) {
console.error("Error in /postNormal endpoint:", error);
res.status(500).json({
error: "An error occurred while processing the API request.",
path: req.params.path,
});
}
});

app.put("/putNormal/:path(*)", async (req, res) => {
try {
const decodedPath = decodeURIComponent(req.params.path);
console.log("Received PUT request to /putNormal with path:", decodedPath);

const response = await axios.put(decodedPath, req.body);
res.json(response.data);
} catch (error) {
console.error("Error in /putNormal endpoint:", error);
res.status(500).json({
error: "An error occurred while processing the API request.",
path: req.params.path,
});
}
});

app.delete("/deleteNormal/:path(*)", async (req, res) => {
try {
const decodedPath = decodeURIComponent(req.params.path);
console.log(
"Received DELETE request to /deleteNormal with path:",
decodedPath
);

const response = await axios.delete(decodedPath);
res.json(response.data);
} catch (error) {
console.error("Error in /deleteNormal endpoint:", error);
res.status(500).json({
error: "An error occurred while processing the API request.",
path: req.params.path,
});
}
});
Loading

0 comments on commit f0d386e

Please sign in to comment.