Skip to content

Commit e0a48f1

Browse files
committed
chore: add pino debug logging for http requests
1 parent 5106b99 commit e0a48f1

File tree

7 files changed

+29
-1
lines changed

7 files changed

+29
-1
lines changed

.devcontainer/.env.production.local.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ GITHUB_CLIENT_ID=
1212
GITHUB_CLIENT_SECRET=
1313
GITHUB_CALLBACK_URL=http://localhost:3000/auth/github/callback
1414

15-
NODE_ENV=production
15+
NODE_ENV=development
1616

1717
REDIS_PORT=6379
1818
REDIS_HOST=redis # using redis service name because the app will run in a container so localhost is not correct

.env.development

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
PORT=3000
22
FRONTEND_URL=http://localhost:3000
3+
4+
DEBUG_LOG=true
35
NODE_ENV=development
46
REDIS_PORT=6379
57
REDIS_HOST=localhost

manual-route-tests/login.http

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
### Valid credentials
2+
GET http://localhost:3000/csrf/token
3+
content-type: application/json
4+
15
### Valid credentials
26
POST http://localhost:3000/auth/login
7+
x-csrf-token: 170691e9ce54052ddca950de19347c36006d47dd9ad66ba8f8e5504d896a336c159877eaa22b3296fada395791765f6225fc1b667125c85f1555a5f4509c2465760793bf49e194256f03738f426a861c27c7f060bd58378159de3df3454dbab6ffc38fe15e10b730c9439aef90ba1a1b5c5f68636d54488498301053f21ee8f2
38
content-type: application/json
49

510
{

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
"passport-github2": "^0.1.12",
100100
"passport-google-oauth20": "^2.0.0",
101101
"pino": "^9.7.0",
102+
"pino-http": "^10.5.0",
102103
"pino-pretty": "^13.0.0",
103104
"qrcode": "^1.5.4",
104105
"react-email": "^4.0.7",

src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const GlobalConfig = {
3636
EMAIL_BACKEND_BASE_URL: process.env.EMAIL_BACKEND_BASE_URL,
3737
EMAIL_ASSETS_BASE_URL: process.env.EMAIL_ASSETS_BASE_URL,
3838
FRONTEND_URL: process.env.FRONTEND_URL,
39+
DEBUG_LOG: Boolean(process.env.DEBUG_LOG),
3940
};
4041

4142
export default GlobalConfig;

src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@ import cors from 'cors';
1818
import { setupSocialAuth } from './routes/social-auth/index.js';
1919
import { registerDevRoutes } from './routes/dev/dev-routes.js';
2020
import { configurePassport } from './routes/social-auth/passport-config.js';
21+
import { pinoHttp } from 'pino-http';
2122

2223
console.log('env:', GlobalConfig.ENV);
2324

2425
const app = express();
2526
const port = GlobalConfig.PORT;
2627

28+
if (GlobalConfig.DEBUG_LOG === true) {
29+
// Create Pino logger middleware
30+
app.use(pinoHttp());
31+
}
32+
2733
app.use(
2834
cors({
2935
origin: GlobalConfig.FRONTEND_URL, // your frontend URL & port here

0 commit comments

Comments
 (0)