-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
60 lines (51 loc) · 1.43 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import express from "express";
import fetch from "node-fetch";
import cors from "cors";
const app = express();
import dotenv from "dotenv";
import nftRouter from "./routes/nft.js";
dotenv.config();
app.use(cors());
app.use("/nft", nftRouter);
app.get("/", (_, res) => {
res.send("Hello World!");
});
app.get("/twitter/verify", async (req, res) => {
const tweet = req.query.tweet;
const randid = req.query.randid;
let twitterOwner = "";
//get tweet owner
const tweetResult = await fetch(
`https://api.twitter.com/2/tweets?ids=${tweet}&expansions=author_id&user.fields=username`,
{
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `Bearer ${process.env.TWITTER_API_KEY}`,
},
}
);
const tweetResultJson = await tweetResult.json();
const tweetText = tweetResultJson.data[0].text;
const tweetRandID = tweetText.substr(25, 20);
const tweetAuthor = tweetResultJson.includes.users[0].username;
if (tweetRandID.toUpperCase() === randid.toUpperCase()) {
res.json({
username: tweetAuthor,
});
} else {
res.json({
username: "RickAstley",
});
}
});
//Server Setup
if (process.env.PORT) {
app.listen(process.env.PORT, process.env.IP, () => {
console.log("Server is running on port " + process.env.PORT);
});
} else {
app.listen(4000, () => {
console.log("Server is running at: http://localhost:4000");
});
}