-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update environment variables and add compression middleware
- Loading branch information
Showing
8 changed files
with
129 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
# App's running environment | ||
NODE_ENV= | ||
NODE_ENV=development | ||
|
||
# App's running port | ||
PORT= | ||
PORT=8080 | ||
|
||
# Cors Origin URL | ||
CORS_ORIGIN="" | ||
|
||
# App's public path | ||
PUBLIC_PATH="/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npx lint-staged |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
import compression from "compression"; | ||
import cors from "cors"; | ||
import express, { Express } from "express"; | ||
import helmet from "helmet"; | ||
import { pino } from "pino"; | ||
import { pinoHttp } from "pino-http"; | ||
|
||
import { middlewares } from "./middleware"; | ||
import compressFilter from "./utils/compress-filter"; | ||
import { getCorsOrigin } from "./utils/env"; | ||
|
||
const logger = pino({ name: "server start" }); | ||
const app: Express = express(); | ||
const cors_origin = getCorsOrigin(); | ||
|
||
// Setup Middlewares | ||
app.use(cors({ credentials: true })); | ||
app.use(cors({ origin: [cors_origin], credentials: true })); | ||
app.use(pinoHttp({ logger })); | ||
app.use(helmet()); | ||
app.use(compression({ filter: compressFilter })); | ||
app.use(middlewares()); | ||
|
||
export { app, logger }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import compression from "compression"; | ||
import type { Request, Response } from "express"; | ||
|
||
/** | ||
* Filter Function for the compression middleware | ||
* @param req HTTPs Request | ||
* @param res HTTPs Response | ||
* @returns Returns false if request header contains x-no-compression | ||
*/ | ||
function compressFilter(req: Request, res: Response): boolean { | ||
if (req.headers["x-no-compression"]) { | ||
// don't compress responses with this request header | ||
return false; | ||
} | ||
|
||
// fallback to standard filter function | ||
return compression.filter(req, res); | ||
} | ||
|
||
export default compressFilter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters