-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
53 lines (46 loc) · 1.09 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"use strict";
require('dotenv').config();
const express = require("express");
const bodyParser = require("body-parser");
const axios = require("axios");
const PORT = process.env.PORT || 3000;
const BASE_URL = process.env.API_URL;
const API_KEY = process.env.API_KEY;
const API_OPTIONS = {
headers: { accept: "application/json" },
timeout: 1000,
responseType: "text"
};
const API = axios.create({
baseURL: BASE_URL,
params: {
accessId: API_KEY,
format: "json"
},
API_OPTIONS
});
const app = express();
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept"
);
next();
});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.post("/", function(req, res) {
API.get(req.body.url, {
params: req.body.params
})
.then(response => {
res.json(response.data);
})
.catch(e => {
console.log(e);
});
});
app.listen(PORT, function() {
console.log('proxify is listening on port %s', PORT)
})