-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
55 lines (46 loc) · 1.17 KB
/
api.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
import * as dotenv from 'dotenv'
dotenv.config();
import { request } from 'undici'
import cors from 'cors'
import express from 'express'
import {IgApiClient} from 'instagram-private-api'
const app = express();
const port = process.env.PORT || 3000;
app.use(cors({
origin: '*'
}));
app.get('/', (req, res) => {
console.log("home")
res.send('Welcome to CORS server 😁')
})
var options = {
'method': 'GET',
'url': 'https://www.instagram.com/asd',
'headers': {
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: '',
variables: {}
})
};
app.get('/getUserInfo/:username', async (req, res) => {
console.log("username")
const ig = new IgApiClient();
ig.state.generateDevice(process.env.IG_USERNAME);
await ig.account.login(process.env.IG_USERNAME, process.env.IG_PASSWORD);
try{
const info = await ig.user.usernameinfo("asdf")
// console.log("info: ",info)
res.send(info)
}catch(err){
console.log("err: ",err)
res.send(err)
}
})
app.get('/cors', (req, res) => {
res.send('This has CORS enabled 🎈')
})
app.listen(8080, () => {
console.log('listening on port 8080')
})