I am creating an app with ionic framework. I created an API via a cheerio scrape afterwards and connected to heroku to make a Hattp call. the problem is that while adding the android platform i get a ‘socket hang up’ error. How can I go about solving the problem? Thank you in advance. This is my code:
JavaScript
x
110
110
1
//code server (index.js)
2
const express = require("express");
3
const ok = require('./srabs')
4
const corsi = require('./corsiS')
5
const app = express();
6
const porta = '8000'
7
var cors = require('cors');
8
var https = require("https");
9
10
11
12
app.use(cors())
13
14
app.get('/', (req, res) => {
15
res.send(Array(ok.Arra, corsi.cors));
16
17
})
18
19
20
21
app.listen(process.env.PORT || 8000, () => {
22
console.log(`Server ex ${porta}`);
23
});
24
25
26
27
exports
28
29
//this is cheerio srcrape n1
30
31
const request = require('request');
32
const cheerio = require('cheerio');
33
const Arra = []
34
const arra2 = []
35
36
37
request('https://wwww.mywebsite.it/', (error, response, html) => {
38
// reset Array on each call
39
40
if (!error && response.statusCode == 200) {
41
const $ = cheerio.load(html)
42
const art = $('article').each((i, el) => {
43
const title = $(el)
44
.find('.entry-title.mh-posts-grid-title')
45
.text();
46
const link = $(el)
47
.find('a')
48
.attr('href');
49
const image = $(el).find('noscript').attr('data-img');
50
51
52
53
Arra.push({ title: [title], link: [link], image: [image] });
54
55
});
56
}
57
}
58
);
59
exports.Arra = Arra;
60
61
//this is cheerio srcrape n2
62
63
const request = require('request');
64
const cheerio = require('cheerio');
65
const KEY_aff = '/?ffverf4fergtrrgefe12321b'
66
const cors = []
67
68
69
70
request('https://curses.it/courses', (error, response, html) => {
71
// reset Array on each call
72
73
if (!error && response.statusCode == 200) {
74
const $ = cheerio.load(html);
75
const art = $('.course-listing').each((i, el) => {
76
const img = $(el).find('.course-box-image-container')
77
.find('img')
78
.attr('src');
79
const link = $(el)
80
.find('a').attr('href')
81
82
83
var http = 'https://curses.it' + link + KEY_aff;
84
85
const title = $(el).find('.course-listing-title').text();
86
const subtitle = $(el).find('.course-listing-subtitle').text();
87
88
cors.push({ title: [title], sub: [subtitle], linkAF: [http], img: [img] });
89
90
})
91
}
92
}),
93
exports.cors = cors;
94
95
//this is error in terminal of ionic
96
97
Error: socket hang up
98
99
at connResetException (node:internal/errors:621:14)
100
at Socket.socketOnEnd (node:_http_client:502:23)
101
at Socket.emit (node:events:339:22)
102
at endReadableNT (node:internal/streams/readable:1289:12)
103
at processTicksAndRejections (node:internal/process/task_queues:80:21)
104
ionic Error: socket hang up
105
ionic at connResetException (node:internal/errors:621:14)
106
ionic at Socket.socketOnEnd (node:_http_client:502:23)
107
ionic at Socket.emit (node:events:339:22)
108
ionic at endReadableNT (node:internal/streams/readable:1289:12)
109
ionic at processTicksAndRejections (node:internal/process/task_queues:80:21) +4s
110
Advertisement
Answer
I solved it, it wasn’t an API problem. I just re-installed the dependencies of: node.js, ionic, crodova- res.