|
1 | 1 | import path from 'path';
|
2 | 2 | import express from 'express';
|
3 |
| -import session from 'express-session'; |
4 |
| -import passport from 'passport'; |
5 | 3 | import { apolloExpress, graphiqlExpress } from 'apollo-server';
|
6 | 4 | import { makeExecutableSchema } from 'graphql-tools';
|
7 |
| -import { Strategy as GitHubStrategy } from 'passport-github'; |
8 | 5 | import bodyParser from 'body-parser';
|
9 |
| -import dotenv from 'dotenv'; |
10 |
| -import knex from './sql/connector'; |
11 |
| - |
12 |
| -const KnexSessionStore = require('connect-session-knex')(session); |
13 |
| -const store = new KnexSessionStore({ |
14 |
| - knex, |
15 |
| -}); |
16 | 6 |
|
| 7 | +import { |
| 8 | + GITHUB_CLIENT_ID, |
| 9 | + GITHUB_CLIENT_SECRET, |
| 10 | +} from './githubKeys'; |
| 11 | +import { setUpGitHubLogin } from './githubLogin'; |
17 | 12 | import { schema, resolvers } from './schema';
|
18 | 13 | import { GitHubConnector } from './github/connector';
|
19 | 14 | import { Repositories, Users } from './github/models';
|
20 | 15 | import { Entries, Comments } from './sql/models';
|
21 | 16 |
|
22 |
| -dotenv.config({ silent: true }); |
23 | 17 | let PORT = 3010;
|
24 | 18 |
|
25 | 19 | if (process.env.PORT) {
|
26 | 20 | PORT = parseInt(process.env.PORT, 10) + 100;
|
27 | 21 | }
|
28 | 22 |
|
29 |
| -const { |
30 |
| - GITHUB_CLIENT_ID, |
31 |
| - GITHUB_CLIENT_SECRET, |
32 |
| -} = process.env; |
33 |
| - |
34 | 23 | const app = express();
|
35 | 24 |
|
36 |
| -app.use(session({ |
37 |
| - secret: 'your secret', |
38 |
| - resave: true, |
39 |
| - saveUninitialized: true, |
40 |
| - store, |
41 |
| -})); |
42 |
| - |
43 |
| -app.use(passport.initialize()); |
44 |
| -app.use(passport.session()); |
45 |
| - |
46 | 25 | app.use(bodyParser.urlencoded({ extended: true }));
|
47 | 26 | app.use(bodyParser.json());
|
48 | 27 |
|
49 |
| -app.use(express.static('dist')); |
50 |
| - |
51 |
| -app.get('/login/github', |
52 |
| - passport.authenticate('github')); |
53 |
| - |
54 |
| -app.get('/login/github/callback', |
55 |
| - passport.authenticate('github', { failureRedirect: '/' }), |
56 |
| - (req, res) => res.redirect('/')); |
57 |
| - |
58 |
| -app.get('/logout', (req, res) => { |
59 |
| - req.logout(); |
60 |
| - res.redirect('/'); |
61 |
| -}); |
| 28 | +setUpGitHubLogin(app); |
62 | 29 |
|
63 | 30 | const executableSchema = makeExecutableSchema({
|
64 | 31 | typeDefs: schema,
|
@@ -115,16 +82,3 @@ app.get('/', (req, res) => {
|
115 | 82 | app.listen(PORT, () => console.log( // eslint-disable-line no-console
|
116 | 83 | `API Server is now running on http://localhost:${PORT}`
|
117 | 84 | ));
|
118 |
| - |
119 |
| -const gitHubStrategyOptions = { |
120 |
| - clientID: GITHUB_CLIENT_ID, |
121 |
| - clientSecret: GITHUB_CLIENT_SECRET, |
122 |
| - callbackURL: 'http://localhost:3000/login/github/callback', |
123 |
| -}; |
124 |
| - |
125 |
| -passport.use(new GitHubStrategy(gitHubStrategyOptions, (accessToken, refreshToken, profile, cb) => { |
126 |
| - cb(null, profile); |
127 |
| -})); |
128 |
| - |
129 |
| -passport.serializeUser((user, cb) => cb(null, user)); |
130 |
| -passport.deserializeUser((obj, cb) => cb(null, obj)); |
0 commit comments