kje za vraga so vejice
commit
a23c87ba63
|
@ -0,0 +1,15 @@
|
||||||
|
FROM node:14-alpine AS development
|
||||||
|
# Add a work directory
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Cache and Install dependencies
|
||||||
|
COPY package.json .
|
||||||
|
RUN yarn install
|
||||||
|
|
||||||
|
COPY index.js .
|
||||||
|
|
||||||
|
# Expose port
|
||||||
|
EXPOSE 1234
|
||||||
|
|
||||||
|
# Start the app
|
||||||
|
CMD [ "yarn", "start"]
|
|
@ -0,0 +1,10 @@
|
||||||
|
version: "3.8"
|
||||||
|
|
||||||
|
services:
|
||||||
|
proski_neki:
|
||||||
|
container_name: proski_neki
|
||||||
|
image: proski_neki
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
ports:
|
||||||
|
- 1234:1234
|
|
@ -0,0 +1,77 @@
|
||||||
|
const express = require("express");
|
||||||
|
const http = require('http');
|
||||||
|
const fetch = require('node-fetch');
|
||||||
|
const https = require('https');
|
||||||
|
const bodyParser = require('body-parser');
|
||||||
|
|
||||||
|
const httpsAgent = new https.Agent({
|
||||||
|
rejectUnauthorized: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
app.use(bodyParser.urlencoded({ extended: true }));
|
||||||
|
app.use(bodyParser.json())
|
||||||
|
|
||||||
|
app.use('/proxy', async (req, res) => {
|
||||||
|
try {
|
||||||
|
// check if there is bearer token with value e8a8aead-95b5-47d0-9a10-2b7478f151bd
|
||||||
|
if (req.headers.authorization != 'Bearer e8a8aead-95b5-47d0-9a10-2b7478f151bd') {
|
||||||
|
res.status(401).json({
|
||||||
|
success: false,
|
||||||
|
code: 401
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// check if there is a proxy-target-url provided in header
|
||||||
|
if (!req.headers['proxy-target-url']) {
|
||||||
|
res.status(400).json({
|
||||||
|
success: false,
|
||||||
|
code: 400
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// copy over the headers from the request, while removing the authorization and Proxy-Target-URL headers
|
||||||
|
let headers = {};
|
||||||
|
for (let key in req.headers) {
|
||||||
|
if (key != 'authorization' && key != 'proxy-target-url') {
|
||||||
|
headers[key] = req.headers[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
headers['host'] = null;
|
||||||
|
// print request body
|
||||||
|
// console.log(req.body);
|
||||||
|
let response = await fetch(req.headers['proxy-target-url'], {
|
||||||
|
method: req.method,
|
||||||
|
headers: headers,
|
||||||
|
body: req.method == 'GET' ? null : JSON.stringify(req.body),
|
||||||
|
agent: httpsAgent
|
||||||
|
});
|
||||||
|
// return the response, with the response header, status code and body
|
||||||
|
console.log(`[${new Date().toLocaleString('bs-Latn-BA')}] ${req.method} ${req.headers['proxy-target-url']}: ${response.status}`);
|
||||||
|
res.status(response.status).json({
|
||||||
|
success: true,
|
||||||
|
headers: response.headers,
|
||||||
|
status: response.status,
|
||||||
|
data: req.headers['proxy-target-url'].includes('https://najava.hzinfra.hr/hzinfo/default.asp') ? await response.buffer() : await response.text(),
|
||||||
|
sent: {
|
||||||
|
url: req.headers['proxy-target-url'],
|
||||||
|
method: req.method,
|
||||||
|
headers: headers,
|
||||||
|
body: req.body,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
code: 500
|
||||||
|
})
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
http.createServer(app).listen(1234, async () => {
|
||||||
|
console.log("Server is running on port 1234");
|
||||||
|
});
|
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"name": "prometko-api",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "API which contains all the API procedures used in the extended Prometko and MestniPromet project",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "exit 0",
|
||||||
|
"start": "node index.js"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/vekejsn/prometko-api.git"
|
||||||
|
},
|
||||||
|
"author": "vekejsn <nedzad@beus.cc>",
|
||||||
|
"license": "ISC",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/vekejsn/prometko-api/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/vekejsn/prometko-api#readme",
|
||||||
|
"dependencies": {
|
||||||
|
"cors": "^2.8.5",
|
||||||
|
"express": "^4.18.1",
|
||||||
|
"node-fetch": "2.6.1"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue