From fe64da15c9208a8dd602f397937e42203bb674bf Mon Sep 17 00:00:00 2001 From: Max-im Date: Wed, 2 Aug 2023 00:49:23 +0300 Subject: [PATCH] add tsc to build --- .github/workflows/production.yml | 5 +- server/src/server.ts | 81 +++++++++++++++++--------------- 2 files changed, 48 insertions(+), 38 deletions(-) diff --git a/.github/workflows/production.yml b/.github/workflows/production.yml index 7e3ab8a..d4acf7f 100644 --- a/.github/workflows/production.yml +++ b/.github/workflows/production.yml @@ -67,6 +67,9 @@ jobs: with: node-version: "14.x" + - name: Build server + run: cd ./server && npm install && tsc + - name: Install dependencies run: cd ./client && npm install @@ -74,7 +77,7 @@ jobs: run: cd ./client && npm run build - name: Copy - run: cd ./client && cp -r build/ ../server/src + run: cd ./client && cp -r build/ ../server/dist deploy: needs: [testing, building] diff --git a/server/src/server.ts b/server/src/server.ts index 883b4de..769b584 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -1,4 +1,4 @@ -import path from 'node:path'; +import path from 'path'; import Fastify, { FastifyReply, FastifyRequest } from 'fastify'; import cors from '@fastify/cors'; import jwt from '@fastify/jwt'; @@ -11,7 +11,14 @@ import logRoutes from './modules/log/log.route'; import { userSchemas } from './modules/user/user.auth.schema'; import { projectSchemas } from './modules/project/project.schema'; import { - DONATE_URL, LOG_URL, NOTIFICATION_URL, PAYMENT_URL, PLAN_URL, PROJECT_URL, STATUS_URL, USER_URL + DONATE_URL, + LOG_URL, + NOTIFICATION_URL, + PAYMENT_URL, + PLAN_URL, + PROJECT_URL, + STATUS_URL, + USER_URL, } from './util/urls'; import planRoutes from './modules/plan/plan.route'; import notificationRoutes from './modules/notification/notification.route'; @@ -21,53 +28,53 @@ import donateRoutes from './modules/donate/donate.route'; import './jobs'; declare module 'fastify' { - export interface FastifyInstance { - // eslint-disable-next-line - registredUser: any; - } + export interface FastifyInstance { + // eslint-disable-next-line + registredUser: any; + } } declare module '@fastify/jwt' { - interface FastifyJWT { - user: { - id: string; - }; - } + interface FastifyJWT { + user: { + id: string; + }; + } } // eslint-disable-next-line function serverBuilder(options: { [key: string]: any } = {}) { - const logger = options.logger || true; - const server = Fastify({ logger }); + const logger = options.logger || true; + const server = Fastify({ logger }); - server.decorate('registredUser', registredUserHook); - for (const schema of [...userSchemas, ...projectSchemas]) { - server.addSchema(schema); - } + server.decorate('registredUser', registredUserHook); + for (const schema of [...userSchemas, ...projectSchemas]) { + server.addSchema(schema); + } - server.register(fastifyStatic, { - root: path.join(__dirname, 'build'), - wildcard: false, - }); + server.register(fastifyStatic, { + root: path.join(__dirname, 'build'), + wildcard: false, + }); - server.get('/*', (request: FastifyRequest, reply: FastifyReply) => { - // @ts-ignore - reply.sendFile('index.html'); - }); + server.get('/*', (request: FastifyRequest, reply: FastifyReply) => { + // @ts-ignore + reply.sendFile('index.html'); + }); - server.register(jwt, { secret: process.env.SECRET_OR_KEY }); - server.register(cors, {}); - server.register(statusRoutes, { prefix: STATUS_URL }); - server.register(userRoutes, { prefix: USER_URL }); - server.register(projectRoutes, { prefix: PROJECT_URL }); - server.register(logRoutes, { prefix: LOG_URL }); - server.register(planRoutes, { prefix: PLAN_URL }); - server.register(notificationRoutes, { prefix: NOTIFICATION_URL }); - server.register(paymentRoutes, { prefix: PAYMENT_URL }); - server.register(donateRoutes, { prefix: DONATE_URL }); - server.register(senderRoutes, { prefix: 'api/v1/send' }); + server.register(jwt, { secret: process.env.SECRET_OR_KEY }); + server.register(cors, {}); + server.register(statusRoutes, { prefix: STATUS_URL }); + server.register(userRoutes, { prefix: USER_URL }); + server.register(projectRoutes, { prefix: PROJECT_URL }); + server.register(logRoutes, { prefix: LOG_URL }); + server.register(planRoutes, { prefix: PLAN_URL }); + server.register(notificationRoutes, { prefix: NOTIFICATION_URL }); + server.register(paymentRoutes, { prefix: PAYMENT_URL }); + server.register(donateRoutes, { prefix: DONATE_URL }); + server.register(senderRoutes, { prefix: 'api/v1/send' }); - return server; + return server; } export default serverBuilder;