chore: update environment configuration and deployment scripts

- Added production environment variables to docker-compose.yml
- Updated Dockerfile for API and web to use Turbo build commands
- Modified turbo.json to include new environment variables
- Updated API index.ts to use new environment configuration
- Updated README.md with correct API port
- Added start:api script to package.json
- Improved deployment and configuration management
This commit is contained in:
Juan Sebastián Montoya 2025-03-06 23:08:10 -05:00
parent 9a2e69921e
commit 1e5a035d33
7 changed files with 28 additions and 17 deletions

View file

@ -11,19 +11,21 @@ import { z } from 'zod';
dotenv.config({ path: '../../.env' });
const envs = z
const { allowedOrigins, port, host } = z
.object({
ALLOWED_ORIGINS: z.string().default('http://localhost:5173'),
ALLOWED_ORIGINS: z.string(),
API_HOST: z.string(),
API_PORT: z.coerce.number(),
})
.transform((env) => {
return {
allowedOrigins: env.ALLOWED_ORIGINS.split(','),
port: env.API_PORT,
host: env.API_HOST,
};
})
.parse(process.env);
console.log(envs);
const app = fastify({
logger: true,
exposeHeadRoutes: true,
@ -41,8 +43,7 @@ const context = async (req: FastifyRequest) => {
app.register(fastifyCors, {
origin: (origin, callback) => {
if (envs.allowedOrigins.includes(origin || '*'))
return callback(null, true);
if (!origin || allowedOrigins.includes(origin)) return callback(null, true);
return callback(new Error('Not allowed'), false);
},
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
@ -52,7 +53,6 @@ app.register(fastifyCors, {
app.register(mercurius, {
schema,
subscription: true,
graphiql: true,
context,
});
@ -75,7 +75,7 @@ mercuriusCodegen(app, {
},
});
app.listen({ port: 8080 }, (err, address) => {
app.listen({ host, port }, (err, address) => {
if (err) {
console.error(err);
process.exit(1);