Skip to content

Commit

Permalink
Merge pull request #10 from caions/fix/swagger-vercel-cors
Browse files Browse the repository at this point in the history
chore: add cors vercel json
  • Loading branch information
caions committed Oct 4, 2023
2 parents 6acb8b9 + fcf768f commit f7e135e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
3 changes: 1 addition & 2 deletions habits-document.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"swagger": "2.0",
"info": {
"version": "1.1.2",
"version": "1.1.3",
"title": "Habit Tracker API",
"description": "Api to manage habits"
},
"host": "habit-tracker-backend.vercel.app",
"basePath": "/",
"schemes": [
"http",
"https"
],
"paths": {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "habit-tracker-backend",
"version": "1.1.2",
"version": "1.1.3",
"description": "",
"main": "index.js",
"scripts": {
Expand All @@ -12,7 +12,7 @@
"lint:check": "eslint .",
"lint:fix": "eslint --fix .",
"versel-build": "echo hello",
"doc": "ts-node-dev --quiet src/infra/web/swagger/swagger.ts"
"doc": "env NODE_ENV=development ts-node-dev --quiet src/infra/web/swagger/swagger.ts"
},
"keywords": [],
"author": "Caio Nascimento",
Expand Down
9 changes: 1 addition & 8 deletions src/infra/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,7 @@ app.use(express.json());
app.use(loggerMiddleware);
app.use(routes);
app.use(errorHandler);
const CSS_URL =
'https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.1.0/swagger-ui.min.css';

app.use(
'/doc',
swaggerUi.serve,
swaggerUi.setup(swaggerFile, { customCssUrl: CSS_URL }),
);
app.use('/doc', swaggerUi.serve, swaggerUi.setup(swaggerFile));
app.get('/', (_, res: Response) => res.json('api version: ' + version));
app.listen(PORT, () => {
executeMigrations(), logger.info(`server running on localhost:${PORT}`);
Expand Down
19 changes: 18 additions & 1 deletion vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,22 @@
"rewrites": [{ "source": "/(.*)", "destination": "/api" }],
"git": {
"deploymentEnabled": false
}
},
"headers": [
{
"source": "/(.*)",
"headers": [
{ "key": "Access-Control-Allow-Credentials", "value": "true" },
{ "key": "Access-Control-Allow-Origin", "value": "*" },
{
"key": "Access-Control-Allow-Methods",
"value": "GET,OPTIONS,PATCH,DELETE,POST,PUT"
},
{
"key": "Access-Control-Allow-Headers",
"value": "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version"
}
]
}
]
}

0 comments on commit f7e135e

Please sign in to comment.