Skip to content

Commit

Permalink
add helmet and local env"
Browse files Browse the repository at this point in the history
  • Loading branch information
mariovyord committed Dec 14, 2023
1 parent 008b89f commit 0fd3252
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
NODE_ENV=development
PORT=5000
ALLOW_ORIGIN="*"
ALLOW_METHODS="GET,PUT,POST,PATCH,DELETE,HEAD,OPTIONS"
ALLOW_HEADERS="Content-Type,Cache-Control,Expires"
JWT_SECRET=SUPERSECRET
CONNECTION_STRING="mongodb://localhost:27017/express-template"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.env
.env.dev
.env.local
dist
node_modules
.npm
9 changes: 9 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"helmet": "^7.1.0",
"joi": "^17.11.0",
"jsonwebtoken": "^9.0.2",
"mongoose": "^8.0.2",
Expand Down
2 changes: 2 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import loggerMiddleware from "./middleware/logger-middleware";
import getConfig from "./config/get-config";
import * as swaggerDoc from "../swagger.json";
import swagger from "swagger-ui-express";
import helmet from "helmet";

/**
* The ExpressJS app
Expand All @@ -21,6 +22,7 @@ app.enable("trust proxy");

const config = getConfig();

app.use(helmet());
app.use(
cors({
origin: config.ALLOW_ORIGIN?.split(",").map((x) => x.trim()),
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { AppError } from "./utils/app-error";
* Load enviroment variables
*/
dotenv.config();
dotenv.config({ path: `.env.local`, override: true });

const config = getConfig();
const port: number = config.PORT ? parseInt(config.PORT) : 5000;
Expand Down

0 comments on commit 0fd3252

Please sign in to comment.