Skip to content

Commit

Permalink
init, get request redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
Piootrekk committed Dec 28, 2023
0 parents commit 05703a8
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Pliki środowiskowe
.env
# Express.js ignore files
node_modules/
dist/

package-lock.json
*.log
*.gz
*.log

/.vscode
/.idea
*.tmp
*.temp
*.bak

# Logi błędów
npm-debug.log*

# Plik konfiguracyjny Yarn
.yarn

# Pliki tymczasowe Windows
Thumbs.db
Desktop.ini
$RECYCLE.BIN/

# Pliky Visual Studio Code
.vscode/
*.code-workspace

# Katalog yarn cache
.yarn/cache/
.yarn/unplugged/
.yarn/build-state.yml

# Katalogi specyficzne dla różnych narzędzi
.idea/
.eslintcache
.pnp/
.pnpm/
npm-debug.log*
yarn-error.log*
42 changes: 42 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const express = require("express");
const axios = require("axios");

const app = express();
const port = 3001;
app.listen(port, () => console.log(`Server listening on port ${port}`));
app.use(express.json());

app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
next();
});

app.get("/", (req, res) => {
res.send("Just a simple proxy server.");
});

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

const response = await axios.get(req.params.path);
res.json(response.data);
});

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

const response = await axios.get(decodedPath, {
params: req.query,
});

res.json(response.data);
} 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,
});
}
});
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "expressproxy",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^1.6.3",
"express": "^4.18.2"
},
"devDependencies": {
"nodemon": "^3.0.2"
}
}

0 comments on commit 05703a8

Please sign in to comment.