Skip to content

Commit

Permalink
Adding front end url as var to set that in the deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
MatheusSanchez committed Jan 29, 2024
1 parent f3ea436 commit 2c67555
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
NODE_ENV=dev
PORT=3333
DATABASE_URL="postgresql://docker:docker@localhost:8080/orange-db?schema=public"
JWT_SECRET=
JWT_SECRET=
FRONTEND_URL="http://127.0.0.1:5173" # http://localhost:5173
1 change: 1 addition & 0 deletions .github/workflows/run-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ jobs:
env:
DATABASE_URL: "postgresql://docker:docker@localhost:8080/orange-db?schema=public"
JWT_SECRET: "oPedroEhFeraMsmCaraEhDiferenciado"
FRONTEND_URL: "FRONTEND_URL"

3 changes: 1 addition & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { logMiddleware } from './controller/middlewares/logMiddleware'
export const app = fastify()

app.register(cors, {
origin: ['http://127.0.0.1:5173', 'http://localhost:5173'],
origin: [env.FRONTEND_URL],
})
app.register(userRoutes)
app.addHook('preHandler', logMiddleware)
Expand All @@ -21,7 +21,6 @@ app.register(fastifyJwt, {
secret: env.JWT_SECRET,
})


app.setErrorHandler((error, _, response) => {
if (env.NODE_ENV !== 'production') {
console.error(error)
Expand Down
3 changes: 2 additions & 1 deletion src/env/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const envSchema = z.object({
NODE_ENV: z.enum(['dev', 'test', 'production']).default('dev'),
PORT: z.coerce.number().default(3333),
DATABASE_URL: z.string(),
JWT_SECRET: z.string()
JWT_SECRET: z.string(),
FRONTEND_URL: z.string(),
})

const _env = envSchema.safeParse(process.env)
Expand Down

0 comments on commit 2c67555

Please sign in to comment.