如何解决nodejs在生产环境Heroku中不起作用,而在开发环境中在我的本地主机中则完全正常
过去一周以来,我一直陷入这段代码中。我正在建立我的第一个项目是youtube / instagram视频下载器,使用香草js(jquery的位)和nodejs作为后端语言。我不知道为什么它在开发中不能很好地在生产中工作。
我只是想使用该链接抓取instagram并获取视频链接,以便我可以使用 这是我的视频元素中的src值
*** instaController.js ***
const cheerio = require('cheerio')
const axios = require('axios')
exports.download = async function (req,res,next) {
try {
const html = await axios({
method: 'get',url: req.body.url
})
const $ = cheerio.load(html.data)
const videoLink = $("meta[property='og:video']").attr("content")
const poster = $("meta[property='og:image']").attr("content")
const type = $("meta[property='og:type']").attr("content")
const site = $("meta[property='og:site_name']").attr("content")
const description = $("meta[property='og:description']").attr("content")
res.locals.data = {
videoLink,type,site,poster,description
}
next()
} catch (e) {
console.log('axiosError:',e.message)
res.status(200).json({
error: "Something went wrong"
})
}
}
frontendJs.js
const res = await axios({
method: 'post',url: '/download/instagram',data: {
url: input.value
}
})
//console.log(res.data)
if (!res.data.error) {
$('#form-elements').html(res.data)
} else {
alert('danger','Invalid link')
}
*** insta.ejs ***
<%if(data.videoLink){%>
<div class="col-12 mx-auto p-3 p-lg-3 mb-5">
<h3 class="text-center">Long Press/Right Click the Video to download :)</h3>
</div>
<div class="col-12 mx-auto p-3 p-lg-3 video">
<video id="video" src="<%= data.videoLink%>" controls type="<%= data.type%>" poster="<%=data.poster%>"
class="mx-auto" playsinline></video>
</div>
<div class="col-12 insta-details p-1 p-lg-3">
<h2 class="text-center">Info</h2>
<div class="row justify-content-center align-items-center my-4">
<div class="col">Type</div>
<div class="col" id="type"><%= data.site%> <%= data.type%></div>
</div>
<hr>
<div class="row justify-content-center align-items-center">
<div class="col">Description</div>
<div class="col" id="desc"><%= data.description%></div>
</div>
</div>
<%}else{%>
<div class="col-12 insta-details p-1 p-lg-3 d-flex align-items-center justify-content-center">
<h3 class="text-center">Sorry No Such Video or Video from private account :( </h3>
</div>
<%}%>
但是ejs的其他部分会在生产环境中返回,但是在我的localhost中,相同的代码返回ejs的if部分。我非常困惑!请帮助我从这种情况中恢复过来:(预先感谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。