-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
92 lines (80 loc) · 2.14 KB
/
index.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
87
88
89
90
91
92
import Fastify from 'fastify'
import fastifyCookie from '@fastify/cookie'
import fastifyView from '@fastify/view'
const { Liquid } = require("liquidjs");
import fastifyFormbody from '@fastify/formbody'
import fastifyJwt from '@fastify/jwt'
import { routesRoot } from './routes/root';
import { routesUser } from './routes/user';
import { join } from 'path'
import * as Sentry from '@sentry/node';
import { nodeProfilingIntegration } from "@sentry/profiling-node";
import { readFileSync } from 'fs';
import { join as pathJoin } from 'path';
import { printInfo } from './lib/utils';
const { ADDRESS = 'localhost', PORT = '3000' } = process.env;
declare module "@fastify/jwt" {
interface FastifyJWT {
user: {
id: string,
mastodonHandle: string,
token: string,
instance: string,
}
}
}
export const app = Fastify({
logger: true
})
if (process.env.SENTRY_DSN) {
Sentry.init({
dsn: process.env.SENTRY_DSN,
integrations: [
nodeProfilingIntegration(),
],
tracesSampleRate: 1.0,
profilesSampleRate: 1.0,
});
}
let version = "development"
const gitRevPath = pathJoin(__dirname, '.git-rev')
if (require('fs').existsSync(gitRevPath)) {
version = readFileSync(gitRevPath, 'utf-8').trim()
}
app.register(fastifyCookie)
app.register(fastifyFormbody)
app.register(fastifyView, {
engine: {
liquid: new Liquid({
root: join(__dirname, "views"),
extname: ".liquid",
globals: {
version,
}
})
},
root: join(__dirname, "views"),
production: false,
maxCache: 0,
options: {
noCache: true,
},
});
app.register(require('@fastify/static'), {
root: join(__dirname, 'public'),
})
app.register(fastifyJwt, {
secret: process.env.JWT_SECRET ?? 'this_shoudl_not_be_used_in_production',
cookie: {
cookieName: 'token',
signed: false,
}
})
app.register(routesRoot)
app.register(routesUser)
app.listen({ host: ADDRESS, port: parseInt(PORT, 10) }, function (err, address) {
if (err) {
app.log.error(err)
}
})
printInfo();