Skip to content

Commit 0560ee6

Browse files
committed
requested changes
1 parent e53c43e commit 0560ee6

File tree

8 files changed

+64
-62
lines changed

8 files changed

+64
-62
lines changed

netlify-functions/getBlogs.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
const axios = require('axios');
2-
const xml2js = require("xml2js");
1+
const axios = require("axios");
2+
const xml2js = require("xml2js");
33

44
exports.handler = async (event, context, callback) => {
5-
const mediumURL = "https://medium.com/feed/codeuino";
6-
try{
7-
const response = await axios.get(`${mediumURL}`);
8-
const data = response.data;
9-
xml2js.parseString(data, (err, result) => {
10-
const sendthis = result.rss.channel[0].item.slice(0, 3)
11-
callback(null, {
12-
statusCode: 200,
13-
headers: {
14-
'Access-Control-Allow-Origin': '*'
15-
},
16-
body: JSON.stringify(sendthis)
17-
})
18-
});
19-
} catch(err) {
20-
console.log(err);
21-
}
22-
}
5+
const mediumURL = "https://medium.com/feed/codeuino";
6+
try {
7+
const response = await axios.get(`${mediumURL}`);
8+
const data = response.data;
9+
xml2js.parseString(data, (err, result) => {
10+
const sendthis = result.rss.channel[0].item.slice(0, 3);
11+
callback(null, {
12+
statusCode: 200,
13+
headers: {
14+
"Access-Control-Allow-Origin": "*"
15+
},
16+
body: JSON.stringify(sendthis)
17+
});
18+
});
19+
} catch (err) {
20+
console.log(err);
21+
}
22+
};

netlify-functions/getLikedTweets.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
const axios = require("axios");
1+
const TwitterAxios = require("../src/helpers/twitterAxios");
22

33
exports.handler = async (event, context, callback) => {
44
try {
5-
const TwitterApi = axios.create({
6-
baseURL: "https://api.twitter.com/1.1",
7-
headers: {
8-
Authorization:
9-
"Bearer AAAAAAAAAAAAAAAAAAAAAEtZGgEAAAAAToMHBHPR1ZpRPIVmo0B9G4syUxs%3DKJpStKohUbcPsI69bLsBOUbwrvpEpDL2JBJ9JuzvnkGDaMZ1Np"
10-
}
11-
});
12-
13-
const likedTweetsResponse = await TwitterApi.get(
5+
const likedTweetsResponse = await TwitterAxios.get(
146
"/favorites/list.json?count=50&screen_name=codeuino"
157
);
168

netlify-functions/getTweets.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
const axios = require("axios");
1+
const TwitterAxios = require("../src/helpers/twitterAxios");
22

33
exports.handler = async (event, context, callback) => {
44
try {
5-
const TwitterApi = axios.create({
6-
baseURL: "https://api.twitter.com/1.1",
7-
headers: {
8-
Authorization:
9-
"Bearer AAAAAAAAAAAAAAAAAAAAAEtZGgEAAAAAToMHBHPR1ZpRPIVmo0B9G4syUxs%3DKJpStKohUbcPsI69bLsBOUbwrvpEpDL2JBJ9JuzvnkGDaMZ1Np"
10-
}
11-
});
12-
13-
const allTweetsResponse = await TwitterApi.get(
5+
const allTweetsResponse = await TwitterAxios.get(
146
"/statuses/user_timeline.json?screen_name=codeuino&count=100"
157
);
168

netlify.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
[ build ]
22
functions = "lambda"
3+
4+
# provide twitter api key
5+
[build.environment]
6+
TWITTER_API_KEY = "AAAAAAAAAAAAAAAAAAAAAEtZGgEAAAAAToMHBHPR1ZpRPIVmo0B9G4syUxs%3DKJpStKohUbcPsI69bLsBOUbwrvpEpDL2JBJ9JuzvnkGDaMZ1Np"

src/components/Medium/Medium.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
import React from "react";
22
import axios from "axios";
33
import "./Medium.css";
4+
import base from "../../helpers/apiBase";
45

56
class Medium extends React.Component {
67
state = {
78
posts: []
89
};
910

1011
componentDidMount() {
11-
const devUrl = 'http://localhost:9000/getBlogs';
12-
const prodUrl = '/.netlify/functions/getBlogs';
1312
axios
14-
.get(process.env.NODE_ENV === "development"? devUrl : prodUrl)
13+
.get(base+"/getBlogs")
1514
.then(res => {
1615
const data = res.data;
1716
console.log(data);
1817
this.setState({
19-
posts: data
18+
posts: data
2019
});
2120
});
2221
}
@@ -38,9 +37,7 @@ class Medium extends React.Component {
3837
}}
3938
></div>
4039
<div className="fading-box">
41-
<div className="view-more">
42-
View More
43-
</div>
40+
<div className="view-more">View More</div>
4441
</div>
4542
</a>
4643
</div>

src/components/NavBar/NavBar.css

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
1-
#myNav{
2-
background-color: white;
1+
#myNav {
2+
background-color: white;
33
}
44

55
.nav-item {
6-
margin-left: 10px;
6+
margin-left: 10px;
77
}
88

99
.navbar-scroll {
10-
box-shadow: 0px 2px 15px grey;
10+
box-shadow: 0px 2px 15px grey;
1111
}
1212

1313
a {
14-
transition: transform 0.6s;
14+
transition: transform 0.6s;
1515
}
1616

17-
a:hover{
18-
text-decoration:none;
19-
transform: scale(1.05);
17+
a:hover {
18+
text-decoration: none;
19+
transform: scale(1.05);
2020
}
2121

22-
.nav-link:visited{
23-
color: rgba(0, 0, 0, 0.7);
22+
.nav-link:visited {
23+
color: rgba(0, 0, 0, 0.7);
2424
}
2525

26-
.nav-link.active, .nav-link.disabled, .nav-link:focus, .nav-link {
27-
color: rgba(0, 0, 0, 0.7) !important;
26+
.nav-link.active,
27+
.nav-link.disabled,
28+
.nav-link:focus,
29+
.nav-link {
30+
color: rgba(0, 0, 0, 0.7) !important;
2831
}
2932

30-
.blue:hover{
31-
color : lightblue;
32-
}
33+
.blue:hover {
34+
color: lightblue;
35+
}

src/helpers/apiBase.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default process.env.NODE_ENV === "development"
2+
? "http://localhost:9000"
3+
: "/.netlify/functions";

src/helpers/twitterAxios.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const axios = require("axios");
2+
3+
const TwitterAxios = axios.create({
4+
baseURL: "https://api.twitter.com/1.1",
5+
headers: {
6+
Authorization:
7+
`Bearer ${process.env.TWITTER_API_KEY}`
8+
}
9+
});
10+
11+
module.exports = TwitterAxios;

0 commit comments

Comments
 (0)