1
0
mirror of https://github.com/microsoft/TypeScript-Node-Starter.git synced 2025-11-09 12:18:52 +00:00

initial commit

This commit is contained in:
Bowden Kelly
2017-05-09 13:28:09 -07:00
parent 352392a682
commit 6625b87b19
171 changed files with 21929 additions and 246 deletions

33
src/controllers/api.ts Normal file
View File

@@ -0,0 +1,33 @@
"use strict";
import * as async from "async";
import * as request from "request";
import * as graph from "fbgraph";
import {Response, Request, NextFunction} from "express";
/**
* GET /api
* List of API examples.
*/
export let getApi = (req: Request, res: Response) => {
res.render("api/index", {
title: "API Examples"
});
};
/**
* GET /api/facebook
* Facebook API example.
*/
export let getFacebook = (req: Request, res: Response, next: NextFunction) => {
const token = req.user.tokens.find((token: any) => token.kind === "facebook");
graph.setAccessToken(token.accessToken);
graph.get(`${req.user.facebook}?fields=id,name,email,first_name,last_name,gender,link,locale,timezone`, (err: Error, results: graph.FacebookUser) => {
if (err) { return next(err); }
res.render("api/facebook", {
title: "Facebook API",
profile: results
});
});
};