22 lines
599 B
TypeScript
22 lines
599 B
TypeScript
import Fastify from 'fastify';
|
|
import { env } from './env.js';
|
|
import { createVultrInstance } from './vultr.js';
|
|
|
|
const fastify = Fastify();
|
|
|
|
fastify.post('/webhook', async (request, reply) => {
|
|
try {
|
|
const instance = await createVultrInstance();
|
|
console.log('Created instance:', instance);
|
|
return { status: 'ok', instance };
|
|
} catch (err: any) {
|
|
console.error(err);
|
|
reply.status(500).send({ status: 'error', message: err.message });
|
|
}
|
|
});
|
|
|
|
fastify.listen({ port: env.WEBHOOK_PORT }, (err, addr) => {
|
|
if (err) throw err;
|
|
console.log(`Server listening at ${addr}`);
|
|
});
|