-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.mjs
76 lines (65 loc) · 1.87 KB
/
index.mjs
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
import path from 'path'
import { fileURLToPath } from 'url';
import Fastify from 'fastify'
import mongodb from '@fastify/mongodb'
import cookie from '@fastify/cookie'
import servestatic from '@fastify/static'
import {
twitterLoginUrl,
twitterAuth,
twitterDeAuth,
twitterMe,
followingOnTwitter,
} from './api/twitter.mjs'
import {
mastodonLoginUrl,
mastodonAuth,
mastodonDeAuth,
mastodonMe,
} from './api/mastodon.mjs'
import {
addOrUpdateTwitterToMastodonMapping,
matchTwitterUserToMastodon,
} from './api/user-matching.mjs'
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = Fastify({
logger: true,
disableRequestLogging: true,
trustProxy: true,
})
app.register(mongodb, {
// force to close the mongodb connection when app stopped
// the default value is false
forceClose: true,
url: process.env.MongoUrl,
})
app.register(cookie, {
secret: process.env.CookieSecret,
parseOptions: {
maxAge: 3600,
sameSite: 'strict',
// secure: true,
}
})
app.register(servestatic, {
root: path.join(__dirname, 'public'),
})
app.get('/twitterLoginUrl', twitterLoginUrl)
app.get('/twitterAuth', twitterAuth)
app.get('/twitterDeAuth', twitterDeAuth)
app.get('/twitterMe', twitterMe)
app.get('/mastodonLoginUrl', mastodonLoginUrl)
app.get('/mastodonAuth', mastodonAuth)
app.get('/mastodonDeAuth', mastodonDeAuth)
app.get('/mastodonMe', mastodonMe)
app.get('/followingOnTwitter', followingOnTwitter)
app.get('/addOrUpdateTwitterToMastodonMapping', addOrUpdateTwitterToMastodonMapping)
app.post('/matchTwitterUserToMastodon', matchTwitterUserToMastodon)
app.listen({ host: '::', port: process.env.PORT ?? 3000 }, function (err, address) {
if (err) {
app.log.error(err)
process.exit(1)
}
// Server is now listening on ${address}
})