Skip to content
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

add cors #5

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ DB_PASSWORD=
DB_NAME=
REFRESH_TOKEN_SECRET=
JWKS_URI=
PRIVATE_KEY=
PRIVATE_KEY=
ADMIN_DASHBOARD_URL=
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@types/bcrypt": "^5.0.1",
"@types/bcryptjs": "^2.4.6",
"@types/cookie-parser": "^1.4.7",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/express-validator": "^3.0.0",
"@types/http-errors": "^2.0.4",
Expand Down Expand Up @@ -57,6 +58,7 @@
"dependencies": {
"bcryptjs": "^2.4.3",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.19.1",
"express-jwt": "^7.7.8",
Expand Down
9 changes: 8 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import "reflect-metadata";

import cors from "cors";
import express, { Request, Response, NextFunction } from "express";
import cookieParser from "cookie-parser";
import logger from "./config/logger";
import { HttpError } from "http-errors";
import authRouter from "./routes/auth";
import tenantRouter from "./routes/tenant";
import userRouter from "./routes/user";
import { Config } from "./config";

const app = express();
app.use(
cors({
origin: [Config.ADMIN_DASHBOARD_URL!],
credentials: true,
}),
);
app.use(express.static("public"));
app.use(cookieParser());
app.use(express.json());
Expand Down
2 changes: 2 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const {
REFRESH_TOKEN_SECRET,
JWKS_URI,
PRIVATE_KEY,
ADMIN_DASHBOARD_URL,
} = process.env;

export const Config = {
Expand All @@ -29,4 +30,5 @@ export const Config = {
REFRESH_TOKEN_SECRET,
JWKS_URI,
PRIVATE_KEY,
ADMIN_DASHBOARD_URL,
};
Loading