-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
26 lines (23 loc) · 698 Bytes
/
Copy pathserver.js
File metadata and controls
26 lines (23 loc) · 698 Bytes
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
import CircularJSON from 'circular-json';
import express from 'express';
import path from 'path';
const app = express();
import axios from 'axios';
let __dirname = path.dirname('')
app.use(express.urlencoded({extended: true}))
app.use(express.json());
app.use(express.static(__dirname + '/build'))
app.post('/req', (req, res) => {
const options = req.body;
console.log(options)
axios.request(options).then((response) => {
let json = CircularJSON.stringify(response)
res.json(json)
}).catch((error) => {
res.json(error.json());
})
})
app.get('/', (req, res) => {
res.sendFile(__dirname + '/build/index.html')
})
app.listen(process.env.PORT || 4000)