-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
33 lines (28 loc) · 885 Bytes
/
server.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
require('dotenv').config()
const config = require('./config')
const Twitter = require('twitter')
const express = require('express')
const client = new Twitter(config)
const PORT = process.env.PORT || process.env.DEV_PORT;
const app = express()
// Create link to Angular build directory
const distDir = __dirname + "/dist/mini-twitter-deck";
// Use the /dist directory
app.use(express.static(distDir));
// Catch all other invalid routes
app.all('/', function(req, res) {
res.status(200).sendFile(`${distDir}/index.html`);
});
app.get('/statuses/user_timeline', function(req, res){
client.get('statuses/user_timeline', req.query, (error, tweets) => {
if (error) {
console.log(error)
return res.sendStatus(500)
}
res.json(tweets)
})
})
console.log(`Will listen to port ${PORT}`)
app.listen(PORT, () => {
console.log(`Now listening to port ${PORT}`)
})