Skip to content

Commit

Permalink
Merge pull request #118 from NodeFactoryIo/fix/cors-origin
Browse files Browse the repository at this point in the history
Add CORS origin
  • Loading branch information
mpetrunic committed Mar 17, 2020
2 parents 341835f + 5c62a22 commit 57c643e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ BACKEND_CONTAINER_NAME=nodejs-ts-starter-backend
# Docker image tag
IMAGE_TAG=latest

# Frontend app
ORIGIN=https://analytics.hactar.app

# Database settings

# Default user that will be created on first start
Expand All @@ -32,4 +35,5 @@ EMAIL_API_KEY=
EMAIL_API_URL=https://api.sendinblue.com/v3/smtp/email
EMAIL_UPTIME_NOTIF_TEMPLATE_ID=2
# Cron like sintax
UPTIME_NOTIF_RECURRENCE=0 * * * *
UPTIME_NOTIF_RECURRENCE=0 * * * *

5 changes: 5 additions & 0 deletions src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ export class App implements Service {
const router = Router();
if (config.env === "dev") {
router.use(cors() as any);
} else {
router.use(cors({
origin: config.origin,
}) as any);
}

router.get("/", (req: Request, res: Response) => {
res.json({
message: "Welcome stranger!",
Expand Down
1 change: 1 addition & 0 deletions src/Config/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const config = Object.freeze({
port: process.env.DB_PORT || 5432,
user: process.env.DB_USER || "nodefactory",
},
origin: process.env.ORIGIN || "https://analytics.hactar.app",
env: process.env.NODE_ENV || "dev",
port: env.SERVER_PORT || 3000,
jwtKey: process.env.JWT_KEY || "nodefactory",
Expand Down

0 comments on commit 57c643e

Please sign in to comment.