Skip to content

Commit e4b2138

Browse files
committed
Update cors.js
1 parent 6420376 commit e4b2138

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

api/cors.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,27 @@ export default async function handler(request, response) {
55

66
const {status, data} = await getRequest(decodeURIComponent(request.query.url));
77

8-
response.status(status).json(data);
8+
response.status(status).send(data);
99

1010

1111
function getRequest(url) {
1212

1313
return new Promise(resolve => {
1414

15-
url = new URL(url);
16-
17-
const req = https.request({
18-
host: url.hostname,
19-
path: url.pathname + url.search,
20-
method: 'GET',
21-
headers: {
22-
accept: 'application/json'
23-
}
24-
}, (resp) => {
15+
const req = https.get(url, (resp) => {
2516

2617
let data = '';
2718

2819
resp.on('data', (chunk) => {
20+
2921
data += chunk;
22+
3023
});
3124

3225
resp.on('end', () => {
3326

34-
data = JSON.parse(data);
35-
3627
resolve({status: resp.statusCode, data: data});
28+
3729
});
3830

3931
});

0 commit comments

Comments
 (0)