From 157b313fff4b515ad5adfa0af895984456f4c87f Mon Sep 17 00:00:00 2001 From: Juanfran Date: Thu, 20 Feb 2025 19:14:18 +0100 Subject: [PATCH] chore: easier test performance --- apps/api/project.json | 7 +++++++ apps/api/src/serve-dist.ts | 33 +++++++++++++++++++++++++++++++++ apps/api/src/simulate-users.ts | 8 ++++---- package.json | 3 ++- pnpm-lock.yaml | 2 +- 5 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 apps/api/src/serve-dist.ts diff --git a/apps/api/project.json b/apps/api/project.json index 5dc12256..232db583 100644 --- a/apps/api/project.json +++ b/apps/api/project.json @@ -67,6 +67,13 @@ "options": { "command": "pnpm exec tsx apps/api/src/simulate-users.ts" } + }, + "serveDist": { + "executor": "nx:run-commands", + "outputs": [], + "options": { + "command": "pnpm exec tsx apps/api/src/serve-dist.ts" + } } }, "tags": ["scope:server"] diff --git a/apps/api/src/serve-dist.ts b/apps/api/src/serve-dist.ts new file mode 100644 index 00000000..8c9a5a52 --- /dev/null +++ b/apps/api/src/serve-dist.ts @@ -0,0 +1,33 @@ +import Fastify from 'fastify'; +import fastifyStatic from '@fastify/static'; +import path from 'path'; + +const PORT = 4300; + +const fastify = Fastify({ + logger: true, + maxParamLength: 5000, +}); + +console.log(path.join(import.meta.dirname, '../../../dist/apps/web')); + +fastify.register(fastifyStatic, { + root: path.join(import.meta.dirname, '../../../dist/apps/web'), + wildcard: false, +}); + +fastify.get('/*', async (_, reply) => { + return reply.sendFile('index.html'); +}); + +const start = async () => { + try { + await fastify.listen({ port: PORT }); + console.log(`http://localhost:${PORT}`); + } catch (err) { + fastify.log.error(err); + process.exit(1); + } +}; + +start(); diff --git a/apps/api/src/simulate-users.ts b/apps/api/src/simulate-users.ts index 209baad2..319fe542 100644 --- a/apps/api/src/simulate-users.ts +++ b/apps/api/src/simulate-users.ts @@ -4,9 +4,11 @@ import { v4 as uuidv4 } from 'uuid'; /* Tested scenario: -50+fps +pnpm build +pnpm serve-dist +pnpm demo -Production build false +50+fps const NUM_CONNECTIONS = 100; const PORT = 8000; @@ -17,8 +19,6 @@ const MAX_EMITS = 250; Text on Color on Position on - -Without provideStoreDevtools */ const NUM_CONNECTIONS = 100; diff --git a/package.json b/package.json index 2558bd6f..9e4b80f5 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "lint": "nx run-many --all --target=lint --parallel", "format": "nx format:write --libs-and-apps", "demo": "nx run api:demo", - "prepare": "husky" + "prepare": "husky", + "serve-dist": "nx run api:serveDist" }, "engines": { "node": "^22.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b87517a8..baafcfed 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20278,7 +20278,7 @@ snapshots: union@0.5.0: dependencies: - qs: 6.12.3 + qs: 6.13.0 unique-filename@3.0.0: dependencies: