-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [INJICERT-567] Signed-off-by: Hitesh C <[email protected]> * [INJICERT-567] CHanges for demo [ADDED] inji-web-proxy src code Signed-off-by: Hitesh C <[email protected]> --------- Signed-off-by: Hitesh C <[email protected]> Signed-off-by: Vishwa <[email protected]>
- Loading branch information
1 parent
046f049
commit b67508e
Showing
8 changed files
with
133 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
MIMOTO_HOST=http://localhost:8088/v1/mimoto | ||
PORT=3010 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.project | ||
.idea | ||
package-*.json | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Dockerfile | ||
# Use the official Node.js image | ||
FROM node:16.9.1 | ||
|
||
# Create and set the working directory inside the container | ||
WORKDIR /usr/src/app | ||
|
||
# Copy package.json and package-lock.json (if available) | ||
COPY package*.json ./ | ||
|
||
# Install dependencies | ||
RUN npm install | ||
|
||
# Copy the rest of the application code | ||
COPY . . | ||
|
||
# Expose the port on which the app runs | ||
EXPOSE 3010 | ||
|
||
# Run the application | ||
CMD ["node", "proxy_server.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
### Inji Web Proxy | ||
|
||
Inji Web Proxy is express js application which is build to connect Backend Service From Inji Web to Avoid CORS issue. | ||
|
||
|
||
### Environment Variables : | ||
|
||
> MIMOTO_HOST : Update the host url of the Mimoto | ||
> PORT : port in which proxy will run | ||
### Installation Steps : | ||
|
||
> npm i && node ./proxy_server.js | ||
### Usage : | ||
|
||
- Goto InjiWeb [api.ts](../inji-web/src/utils/api.ts) | ||
- In order to avoid CORS, update the **mimotoHost** of Inji Web from Mimoto service url to Inji Web Proxy server url, so that it proxies and bypasses the CORS | ||
- ref : https://localhost:3010 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "proxy-server", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"axios": "^1.6.8", | ||
"body-parser": "^1.20.2", | ||
"cors": "^2.8.5", | ||
"dotenv": "^16.4.5", | ||
"express": "^4.19.2", | ||
"fs": "^0.0.1-security", | ||
"path": "^0.12.7" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const express = require('express'); | ||
const cors = require('cors'); | ||
const axios = require('axios'); | ||
const bodyParser = require('body-parser'); | ||
require('dotenv').config() | ||
|
||
const app = express(); | ||
const PORT = process.env.PORT; | ||
|
||
app.use(express.json()); | ||
app.use(cors()); | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ extended: true })); | ||
|
||
app.all('*', async (req, res) => { | ||
delete req.headers.host | ||
delete req.headers.referer | ||
const API_URL = process.env.MIMOTO_HOST; | ||
const path = req.url | ||
try { | ||
let response = {}; | ||
if(path.indexOf("download") !== -1 ) { | ||
res.setHeader('Access-Control-Allow-Origin', '*'); // Change '*' to specific origin if needed | ||
res.setHeader('Access-Control-Allow-Methods', 'GET,OPTIONS,POST'); // Allow GET requests | ||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization'); // Allow specific headers | ||
|
||
response = await axios({ | ||
method: req.method, | ||
responseType: "arraybuffer", | ||
url: `${API_URL}/v1/mimoto/credentials/download`, | ||
data: new URLSearchParams(req.body), | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
"Accept": 'application/pdf', | ||
'Cache-Control': 'no-cache, no-store, must-revalidate' | ||
} | ||
}); | ||
res.set("Content-Type", "application/pdf"); | ||
res.status(response.status).send(response.data); | ||
} else { | ||
response = await axios({ | ||
method: req.method, | ||
url: `${API_URL}${path}`, | ||
headers: req.headers, | ||
data: new URLSearchParams(req.body) | ||
}); | ||
res.status(response.status).json(response.data); | ||
} | ||
|
||
} catch (error) { | ||
console.error("Error occurred: ", error); | ||
if (error.response) { | ||
res.status(error.response.status).json(error.response.data); | ||
} else { | ||
res.status(500).json({ error: error.message }); | ||
} | ||
} | ||
}); | ||
|
||
app.listen(PORT, () => { | ||
console.log(`Proxy server listening on port ${PORT}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
CI=false | ||
CI=false | ||
REACT_APP_MIMOTO_HOST=http://localhost:3010/v1/mimoto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters