forked from NangoHQ/sample-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
65 lines (54 loc) · 1.75 KB
/
app.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
import Fastify from 'fastify';
import cors from '@fastify/cors';
import { postWebhooks } from './routes/postWebhooks.js';
import { getContacts } from './routes/getContacts.js';
import { getIntegrations } from './routes/getIntegrations.js';
import { getConnections } from './routes/getConnections.js';
import { deleteConnection } from './routes/deleteConnection.js';
import { sendSlackMessage } from './routes/sendSlackMessage.js';
const fastify = Fastify({ logger: false });
fastify.addHook('onRequest', (req, _res, done) => {
console.log(`#${req.id} <- ${req.method} ${req.url}`);
done();
});
await fastify.register(cors, {
origin: ['http://localhost:3000'],
credentials: true,
});
fastify.get('/', async function handler(_, reply) {
await reply.status(200).send({ root: true });
});
/**
* List available integrations
* The one you deployed in nango-integrations/
*/
fastify.get('/integrations', getIntegrations);
/**
* List available connection for one user
*/
fastify.get('/connections', getConnections);
/**
* Delete a connection for one user
*/
fastify.delete('/connections', deleteConnection);
/**
* Receive webhooks from Nango every time a records has been added, updated or deleted
*/
fastify.post('/webhooks-from-nango', postWebhooks);
/**
* List contacts to display in the UI
* Contacts are the records Nango fetched from the different integrations
*/
fastify.get('/contacts', getContacts);
/**
* Send a Slack message to a given Slack user.
*/
fastify.post('/send-slack-message', sendSlackMessage);
try {
const port = process.env['PORT'] ? parseInt(process.env['PORT'], 10) : 3003;
await fastify.listen({ host: '0.0.0.0', port });
console.log(`Listening on http://0.0.0.0:${port}`);
} catch (err) {
console.error(err);
process.exit(1);
}