-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: copy over the API function and install dependencies
- Loading branch information
1 parent
36be9c0
commit 28f5daa
Showing
2 changed files
with
39 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,36 @@ | ||
import * as express from 'express'; | ||
import * as functions from 'firebase-functions'; | ||
import * as httpProxy from 'http-proxy'; | ||
|
||
// // Start writing Firebase Functions | ||
// // https://firebase.google.com/docs/functions/typescript | ||
// | ||
// export const helloWorld = functions.https.onRequest((request, response) => { | ||
// response.send("Hello from Firebase!"); | ||
// }); | ||
const app = express(); | ||
|
||
const proxy = httpProxy | ||
.createProxyServer({ | ||
changeOrigin: true, | ||
headers: { | ||
Authorization: `Bearer ${functions.config().twitter.token}`, | ||
}, | ||
target: 'https://api.twitter.com', | ||
}); | ||
|
||
proxy.on('proxyRes', function(proxyRes, req, res) { | ||
if (process.env.NODE_ENV === 'development') { | ||
res.setHeader('Access-Control-Allow-Origin', '*'); | ||
} else { | ||
res.setHeader('Access-Control-Allow-Origin', 'http://trumpymctweetface.com'); | ||
} | ||
}); | ||
|
||
app.get('/1.1/statuses/user_timeline.json', function(req, res) { | ||
if (req.query.screen_name === 'realDonaldTrump') { | ||
proxy.web(req, res); | ||
} else { | ||
res.sendStatus(403); | ||
} | ||
}); | ||
|
||
app.get('/1.1/statuses/show.json', function(req, res) { | ||
proxy.web(req, res); | ||
}); | ||
|
||
export const api = functions.https.onRequest(app); |