|
@@ -54,51 +54,79 @@ router.route('/a').all((req, res, next) => {
|
|
|
|
|
|
|
|
|
|
|
|
-router.post('/testApi', function(req, res, next) {
|
|
|
-
|
|
|
+router.get('/testApi', function(req, res, next) {
|
|
|
+
|
|
|
+
|
|
|
const options = {
|
|
|
hostname: 'cxcy.ssti.net.cn',
|
|
|
path: "/sso/api",
|
|
|
- method: 'GET'
|
|
|
-
|
|
|
+ method: 'GET',
|
|
|
+ headers: req.headers
|
|
|
};
|
|
|
|
|
|
-
|
|
|
- const backendReq = https.request(options, (res) => {
|
|
|
- console.log(res)
|
|
|
- let data = '';
|
|
|
-
|
|
|
-
|
|
|
- res.on('data', (chunk) => {
|
|
|
- data += chunk;
|
|
|
- });
|
|
|
+
|
|
|
+ const proxyReq = https.request(options, (proxyRes) => {
|
|
|
+
|
|
|
+ res.writeHead(proxyRes.statusCode, proxyRes.headers);
|
|
|
|
|
|
-
|
|
|
- res.on('end', () => {
|
|
|
- console.log(data);
|
|
|
- });
|
|
|
+
|
|
|
+ proxyRes.pipe(res);
|
|
|
});
|
|
|
|
|
|
|
|
|
- backendReq.on('error', (error) => {
|
|
|
+ proxyReq.on('error', (error) => {
|
|
|
console.error(error);
|
|
|
+ res.statusCode = 500;
|
|
|
+ res.end('Internal Server Error');
|
|
|
});
|
|
|
|
|
|
-
|
|
|
- backendReq.end();
|
|
|
+
|
|
|
+ req.pipe(proxyReq);
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-
|
|
|
+});
|
|
|
+
|
|
|
+
|
|
|
+backendReq.on('error', (error) => {
|
|
|
+ console.error(error);
|
|
|
+});
|
|
|
+
|
|
|
+
|
|
|
+backendReq.end();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-
|
|
|
+
|
|
|
})
|
|
|
|
|
|
|