diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1a7194d --- /dev/null +++ b/.gitignore @@ -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* \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..7cdbc71 --- /dev/null +++ b/index.js @@ -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, + }); + } +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..a3987ee --- /dev/null +++ b/package.json @@ -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" + } +}