This commit is contained in:
Andras Bacsai
2022-12-12 14:48:56 +01:00
parent 62f2196a0c
commit 2009dc11db
207 changed files with 9062 additions and 160 deletions

View File

@@ -1,10 +1,11 @@
import { fastifyTRPCPlugin } from '@trpc/server/adapters/fastify';
import fastify from 'fastify';
import { appRouter } from './router';
import { createContext } from './router/context';
import { appRouter } from './trpc';
import { createContext } from './trpc/context';
import cors from '@fastify/cors';
import * as path from 'node:path';
import serve from '@fastify/static';
import autoLoad from '@fastify/autoload';
// import { prisma } from './prisma';
const isDev = process.env['NODE_ENV'] === 'development';
@@ -23,7 +24,16 @@ export function createServer(opts: ServerOptions) {
server.register(cors);
server.register(fastifyTRPCPlugin, {
prefix,
trpcOptions: { router: appRouter, createContext }
trpcOptions: {
router: appRouter,
createContext,
onError({ error, type, path, input, ctx, req }) {
console.error('Error:', error);
if (error.code === 'INTERNAL_SERVER_ERROR') {
// send to bug reporting
}
}
}
});
// Serve static files in production. Static files are generated by `yarn build` in the client folder by SvelteKit.
if (!isDev) {
@@ -40,14 +50,16 @@ export function createServer(opts: ServerOptions) {
return reply.status(200).sendFile('index.html');
});
}
server.get('/api', async () => {
return { status: 'ok' };
server.register(autoLoad, {
dir: path.join(__dirname, 'api'),
options: { prefix: '/api' }
});
const stop = () => server.close();
const start = async () => {
try {
await server.listen({ host: '0.0.0.0', port });
console.log('Server is listening on port', port);
console.log('Coolify server is listening on port', port, 'at 0.0.0.0 🚀');
} catch (err) {
server.log.error(err);
process.exit(1);