feat(api): add new v4 endpoints
This commit is contained in:
parent
2957047219
commit
c958a2a743
@ -7,6 +7,8 @@ import v2DataRoutes from 'routes/v2/data';
|
|||||||
import v2ReportRoutes from 'routes/v2/report';
|
import v2ReportRoutes from 'routes/v2/report';
|
||||||
import v3DataRoutes from 'routes/v3/data';
|
import v3DataRoutes from 'routes/v3/data';
|
||||||
import v3ReportRoutes from 'routes/v3/report';
|
import v3ReportRoutes from 'routes/v3/report';
|
||||||
|
import v4DataRoutes from 'routes/v4/data';
|
||||||
|
import v4ReportRoutes from 'routes/v4/report';
|
||||||
import environment from 'services/environment';
|
import environment from 'services/environment';
|
||||||
|
|
||||||
const server = fastify({ logger: true });
|
const server = fastify({ logger: true });
|
||||||
@ -31,6 +33,8 @@ server.register(v2DataRoutes, { prefix: '/rest/v2' });
|
|||||||
server.register(v2ReportRoutes, { prefix: '/rest/v2' });
|
server.register(v2ReportRoutes, { prefix: '/rest/v2' });
|
||||||
server.register(v3DataRoutes, { prefix: '/rest/v3' });
|
server.register(v3DataRoutes, { prefix: '/rest/v3' });
|
||||||
server.register(v3ReportRoutes, { prefix: '/rest/v3' });
|
server.register(v3ReportRoutes, { prefix: '/rest/v3' });
|
||||||
|
server.register(v4DataRoutes, { prefix: '/rest/v4' });
|
||||||
|
server.register(v4ReportRoutes, { prefix: '/rest/v4' });
|
||||||
|
|
||||||
server.listen({ host: '0.0.0.0', port: environment.port }, (error, address) => {
|
server.listen({ host: '0.0.0.0', port: environment.port }, (error, address) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
21
packages/api/src/routes/v4/data.ts
Normal file
21
packages/api/src/routes/v4/data.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { FastifyInstance, RouteShorthandOptions } from 'fastify';
|
||||||
|
import fetch from 'node-fetch';
|
||||||
|
|
||||||
|
export default (server: FastifyInstance, _options: RouteShorthandOptions, done: () => void) => {
|
||||||
|
server.get('/data/', async (_request, reply) => {
|
||||||
|
try {
|
||||||
|
const databaseUrl =
|
||||||
|
'https://raw.githubusercontent.com/wanhose/cookie-dialog-monster/main/database.json';
|
||||||
|
const fetchOptions = {
|
||||||
|
headers: { 'Cache-Control': 'no-cache' },
|
||||||
|
};
|
||||||
|
const result = await (await fetch(databaseUrl, fetchOptions)).json();
|
||||||
|
|
||||||
|
reply.send({ data: result, success: true });
|
||||||
|
} catch (error) {
|
||||||
|
reply.send({ success: false });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
done();
|
||||||
|
};
|
1
packages/api/src/routes/v4/report.ts
Normal file
1
packages/api/src/routes/v4/report.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export { default as default } from '../v3/report';
|
Loading…
Reference in New Issue
Block a user