-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathapp.js
More file actions
31 lines (23 loc) · 726 Bytes
/
app.js
File metadata and controls
31 lines (23 loc) · 726 Bytes
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
import Fastify from 'fastify';
import FastifyBodyParser from '@fastify/formbody';
import { createEventUrl } from './src/helpers.js';
const app = Fastify({ logger: true });
app.register(FastifyBodyParser);
app.post('/rip_quick_add_api', async (request, reply) => {
const text = request.body.text;
return {
url: createEventUrl(text)
};
});
app.get('/rip_quick_add_api', async (request, reply) => {
const text = request.query.text;
const lang = request.query.lang;
const url = createEventUrl(text, lang);
if (url === null) {
return reply.redirect('https://calendar.google.com/calendar/u/0/r/eventedit');
}
return reply.redirect(url);
});
(async () => {
await app.listen({ port: 3000 });
})();