我正在创建一个带有离子框架的应用程序。之后,我通过cheerio scrape创建了一个API,并连接到heroku进行Hattp调用。问题是,在添加android平台时,我遇到了一个"套接字挂断"错误。我该如何着手解决这个问题?提前谢谢。这是我的代码:
//code server (index.js)
const express = require("express");
const ok = require('./srabs')
const corsi = require('./corsiS')
const app = express();
const porta = '8000'
var cors = require('cors');
var https = require("https");
app.use(cors())
app.get('/', (req, res) => {
res.send(Array(ok.Arra, corsi.cors));
})
app.listen(process.env.PORT || 8000, () => {
console.log(`Server ex ${porta}`);
});
exports
//this is cheerio srcrape n1
const request = require('request');
const cheerio = require('cheerio');
const Arra = []
const arra2 = []
request('https://wwww.mywebsite.it/', (error, response, html) => {
// reset Array on each call
if (!error && response.statusCode == 200) {
const $ = cheerio.load(html)
const art = $('article').each((i, el) => {
const title = $(el)
.find('.entry-title.mh-posts-grid-title')
.text();
const link = $(el)
.find('a')
.attr('href');
const image = $(el).find('noscript').attr('data-img');
Arra.push({ title: [title], link: [link], image: [image] });
});
}
}
);
exports.Arra = Arra;
//this is cheerio srcrape n2
const request = require('request');
const cheerio = require('cheerio');
const KEY_aff = '/?ffverf4fergtrrgefe12321b'
const cors = []
request('https://curses.it/courses', (error, response, html) => {
// reset Array on each call
if (!error && response.statusCode == 200) {
const $ = cheerio.load(html);
const art = $('.course-listing').each((i, el) => {
const img = $(el).find('.course-box-image-container')
.find('img')
.attr('src');
const link = $(el)
.find('a').attr('href')
var http = 'https://curses.it' + link + KEY_aff;
const title = $(el).find('.course-listing-title').text();
const subtitle = $(el).find('.course-listing-subtitle').text();
cors.push({ title: [title], sub: [subtitle], linkAF: [http], img: [img] });
})
}
}),
exports.cors = cors;
//this is error in terminal of ionic
Error: socket hang up
at connResetException (node:internal/errors:621:14)
at Socket.socketOnEnd (node:_http_client:502:23)
at Socket.emit (node:events:339:22)
at endReadableNT (node:internal/streams/readable:1289:12)
at processTicksAndRejections (node:internal/process/task_queues:80:21)
ionic Error: socket hang up
ionic at connResetException (node:internal/errors:621:14)
ionic at Socket.socketOnEnd (node:_http_client:502:23)
ionic at Socket.emit (node:events:339:22)
ionic at endReadableNT (node:internal/streams/readable:1289:12)
ionic at processTicksAndRejections (node:internal/process/task_queues:80:21) +4s
我解决了它,它不是API问题。我刚刚重新安装了的依赖项:node.js,离子,crodova-res.