-
Notifications
You must be signed in to change notification settings - Fork 28
Feature/add pagination #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,8 +3,6 @@ import express from "express"; | |||||||||
| import { existsSync } from "fs"; | ||||||||||
| import path from "path"; | ||||||||||
| import { createJobsApiApp } from "./jobsApiApp.js"; | ||||||||||
| import swaggerUi from "swagger-ui-express"; | ||||||||||
| import swaggerSpec from "./swagger.js"; | ||||||||||
|
|
||||||||||
| const PORT = Number(process.env.PORT || 3001); | ||||||||||
|
|
||||||||||
|
|
@@ -16,28 +14,45 @@ const outputDir = process.env.ELECTRON_OUTPUT_DIR | |||||||||
|
|
||||||||||
| const app = createJobsApiApp({ outputDir }); | ||||||||||
|
|
||||||||||
| // ── Electron static-file serving ─────────────────────────────────────────── | ||||||||||
| // When ELECTRON_STATIC_DIR is set, serve the React production build so that | ||||||||||
| // the Electron window can load everything from http://localhost:<PORT>. | ||||||||||
| const staticDir = process.env.ELECTRON_STATIC_DIR; | ||||||||||
| if (staticDir && existsSync(staticDir)) { | ||||||||||
| app.use(express.static(staticDir)); | ||||||||||
|
|
||||||||||
| // SPA catch-all: return index.html for any non-API route so that React | ||||||||||
| // Router (if used in future) works correctly. | ||||||||||
| app.use((req, res) => { | ||||||||||
| if (req.path.startsWith("/api")) { | ||||||||||
| return res.status(404).json({ error: "Rota não encontrada." }); | ||||||||||
| } | ||||||||||
| res.sendFile(path.join(staticDir, "index.html")); | ||||||||||
| }); | ||||||||||
| async function registerSwaggerDocs() { | ||||||||||
| try { | ||||||||||
| const [{ default: swaggerUi }, { default: swaggerSpec }] = await Promise.all([ | ||||||||||
| import("swagger-ui-express"), | ||||||||||
| import("./swagger.js"), | ||||||||||
| ]); | ||||||||||
|
|
||||||||||
| app.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec)); | ||||||||||
| } catch (error) { | ||||||||||
| // eslint-disable-next-line no-console | ||||||||||
| console.warn("Swagger desabilitado:", error instanceof Error ? error.message : error); | ||||||||||
| } | ||||||||||
| } | ||||||||||
| //Swagger documentacao | ||||||||||
| app.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec)); | ||||||||||
|
|
||||||||||
| app.listen(PORT, () => { | ||||||||||
| // eslint-disable-next-line no-console | ||||||||||
| console.log(`API de vagas rodando em http://localhost:${PORT}`); | ||||||||||
| console.log(`Documentação da API em http://localhost:${PORT}/docs`); | ||||||||||
| async function startServer() { | ||||||||||
| await registerSwaggerDocs(); | ||||||||||
|
|
||||||||||
| // ── Electron static-file serving ───────────────────────────────────────── | ||||||||||
| // When ELECTRON_STATIC_DIR is set, serve the React production build so that | ||||||||||
| // the Electron window can load everything from http://localhost:<PORT>. | ||||||||||
| const staticDir = process.env.ELECTRON_STATIC_DIR; | ||||||||||
| if (staticDir && existsSync(staticDir)) { | ||||||||||
| app.use(express.static(staticDir)); | ||||||||||
|
|
||||||||||
| // SPA catch-all: return index.html for any non-API route so that React | ||||||||||
| // Router (if used in future) works correctly. | ||||||||||
| app.use((req, res) => { | ||||||||||
| if (req.path.startsWith("/api")) { | ||||||||||
| return res.status(404).json({ error: "Rota não encontrada." }); | ||||||||||
|
||||||||||
| return res.status(404).json({ error: "Rota não encontrada." }); | |
| return res | |
| .status(404) | |
| .json({ message: "Rota não encontrada.", error: "Rota não encontrada." }); |
Copilot
AI
Apr 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
O callback de listen sempre loga a URL de /docs, mesmo quando o Swagger falha ao registrar (o registerSwaggerDocs() apenas faz warn). Isso pode gerar logs enganosos e, com ELECTRON_STATIC_DIR, /docs pode cair no catch-all do SPA. Sugestão: fazer registerSwaggerDocs() retornar boolean e logar/registrar a rota apenas quando habilitada.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
swaggerSpecvem de./swagger.js, que hoje resolveapis: [path.resolve("src/**/*.js")](dependente deprocess.cwd()). No Electron o cwd costuma ser o app root, então o glob pode não encontrarbackend/src/**/*.jse a documentação fica incompleta. Sugestão: ajustar o swagger.js para resolver o diretório baseado emimport.meta.url(ou passar um caminho absoluto daqui do server).