-
Notifications
You must be signed in to change notification settings - Fork 1
/
api.ts
86 lines (70 loc) · 2.22 KB
/
api.ts
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import express from 'express'
import bodyParser from 'body-parser'
import get from 'axios'
// import _ from 'lodash'
// import mongoose, { Model, Schema } from 'mongoose'
// import session, { Session } from 'express-session'
// import passport, { StrategyCreated } from 'passport'
// import passportLocalMongoose from 'passport-local-mongoose'
// import github2, { Strategy } from 'passport-github2'
// const GitHubStrategy = github2.Strategy
// import findOrCreate from 'mongoose-findorcreate'
import dotenv from 'dotenv'
dotenv.config()
const app = express()
app.use(bodyParser.urlencoded({ extended: true }))
// app.use(session({
// secret: process.env.SECRET_STRING,
// resave: false,
// saveUninitialized: false
// }))
// app.use(passport.initialize())
// app.use(passport.session())
// mongoose.connect(`${process.env.MONGO_CONN}/link-shortener`)
// console.log('Connected successfully to mongoDB')
// const userSchema: Schema = new mongoose.Schema({
// githubId: String,
// links: [
// {
// link: String,
// shortenedLink: String
// }
// ]
// })
// userSchema.plugin(passportLocalMongoose)
// userSchema.plugin(findOrCreate)
// const User = new mongoose.model('User', userSchema)
// passport.use(User.createStrategy())
// passport.serializeUser((user, done) => {
// done(null, user.id)
// })
// passport.deserializeUser((id, done) => {
// User.findById(id, (err, user) => {
// done(err, user)
// })
// })
// passport.use(new GitHubStrategy({
// clientID: process.env.GITHUB_CLIENT_ID,
// clientSecret: process.env.GITHUB_CLIENT_SECRET,
// callbackURL: "http://127.0.0.1:3000/auth/github/callback"
// },
// function(accessToken, refreshToken, profile, cb) {
// console.log(profile)
// User.findOrCreate({ githubId: profile.id }, function (err, user) {
// return cb(err, user);
// });
// }
// ));
app.get('/api', (req, res) => {
res.send('Hello world from server')
})
// app.get('/auth/github', (req, res) => {
// passport.authenticate('github', { scope: ['profile'] })
// })
// app.get('/auth/github/callback',
// passport.authenticate('github', { failureRedirect: '/' }),
// (req, res) => {
// res.redirect('/')
// }
// )
export const handler = app;