我在将nodejs机器人部署到now.sh
服务时遇到问题,这是我的配置:
index.js
var http = require("http");
var Twit = require("twit");
const tweets = [
{
text: "1",
img: `...`
},
{
text: "2",
img: `...`
},
{
text: "3",
img: `...`
}
];
var T = new Twit({
consumer_key: "...",
consumer_secret: "...",
access_token: "...",
access_token_secret: "...",
timeout_ms: 60 * 1000,
strictSSL: true
});
function postImage() {
console.log("running");
const randomNum = Math.floor(Math.random() * (tweets.length - 0));
T.post(
"media/upload",
{
media_data: tweets[randomNum].img
},
... }
});
}
);
}
http
.createServer(function(req, res) {
if (req.url != "/favicon.ico") {
postImage();
setInterval(postImage, 10000);
}
res.end();
})
.listen();
和now.json
{
"name": "twitter-bot",
"builds": [
{
"src": "./index.js",
"use": "@now/node-server"
}
]
}
在本地测试中,要执行功能,我必须打开localhost:port
,然后重新加载页面以执行功能。
所以,我不知道到底是什么问题?