-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (39 loc) · 1.13 KB
/
index.js
File metadata and controls
44 lines (39 loc) · 1.13 KB
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
const express = require("express");
const app = express();
const TwitterAPI = require( __dirname + '/src/twitter_fetch')
require('dotenv').config();
const PORT = 3000
app.use(express.json())
app.use(express.urlencoded({ extended: true }));
app.get("/api/v1/follower", async (req, res)=> {
if (req.headers.authorization && req.headers.authorization.split(' ')[0] === process.env.APIKEY) {
try{
const fetch_Id = req.query.twitterid
const result = await TwitterID_fetch(fetch_Id)
if(!result.follower){
await res.json({ Error: result });
}
else{
await res.json({ follower: result.follower });
}
}
catch(error){
await res.json(error)
}
}
else{
res.json({Error: 'APIKeyが正しくありません'})
}
})
const TwitterID_fetch = async (fetch_Id) => {
try {
const response = await TwitterAPI(fetch_Id)
return response
}
catch(error) {
console.log(error)
}
};
app.listen(PORT, () => {
console.log(`>Express起動完了 listen:${PORT}`);
});