feat(api): add new report route
This commit is contained in:
parent
ee592ddb89
commit
331c3fda69
@ -4,6 +4,7 @@ import rateLimit from '@fastify/rate-limit';
|
||||
import v1EntriesRoutes from 'routes/v1/entries';
|
||||
import v1ReportRoutes from 'routes/v1/report';
|
||||
import v2DataRoutes from 'routes/v2/data';
|
||||
import v2ReportRoutes from 'routes/v2/report';
|
||||
import environment from 'services/environment';
|
||||
|
||||
const server = fastify({ logger: true });
|
||||
@ -21,6 +22,7 @@ server.register(rateLimit, { max: 1, timeWindow: 30000 });
|
||||
server.register(v1EntriesRoutes, { prefix: '/rest/v1' });
|
||||
server.register(v1ReportRoutes, { prefix: '/rest/v1' });
|
||||
server.register(v2DataRoutes, { prefix: '/rest/v2' });
|
||||
server.register(v2ReportRoutes, { prefix: '/rest/v2' });
|
||||
|
||||
server.listen({ host: '0.0.0.0', port: environment.port }, (error, address) => {
|
||||
if (error) {
|
||||
|
40
packages/api/src/routes/v2/report.ts
Normal file
40
packages/api/src/routes/v2/report.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { FastifyInstance, RouteShorthandOptions } from 'fastify';
|
||||
import { sendMail } from 'services/mailing';
|
||||
|
||||
type PostReportBody = {
|
||||
url: string;
|
||||
version: string;
|
||||
};
|
||||
|
||||
export default (server: FastifyInstance, options: RouteShorthandOptions, done: () => void) => {
|
||||
server.post<{ Body: PostReportBody }>(
|
||||
'/report/',
|
||||
{
|
||||
schema: {
|
||||
body: {
|
||||
properties: {
|
||||
url: {
|
||||
type: 'string',
|
||||
},
|
||||
version: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
required: ['url', 'version'],
|
||||
type: 'object',
|
||||
},
|
||||
},
|
||||
},
|
||||
async (request, reply) => {
|
||||
const { url, version } = request.body;
|
||||
const html = `<b>Site:</b> ${url}<br/><b>Version:</b> ${version}`;
|
||||
const subject = 'Cookie Dialog Monster Report';
|
||||
const to = 'hello@wanhose.dev';
|
||||
|
||||
sendMail({ html, to, subject });
|
||||
reply.send({ success: true });
|
||||
}
|
||||
);
|
||||
|
||||
done();
|
||||
};
|
Loading…
Reference in New Issue
Block a user