Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ pnpm test

---

linked PR 5
linked PR 5,4

## 📄 License

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"jsonwebtoken": "9.0.2",
"mongoose": "7.6.3",
"uuid": "9.0.1",
"winston": "3.11.0"
"winston": "3.11.0",
"zod": "^4.4.3"
},
"devDependencies": {
"@types/bcryptjs": "2.4.6",
Expand Down
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

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

17 changes: 10 additions & 7 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@ import logger from './config/logger';
import { corsOptionsDelegate, helmetOptions } from './config/security';
import errorHandler from './middleware/errorHandler';
import routes from './routes';
import env from './config/env';

const app = express();

// Trust the first proxy (load balancer / reverse proxy) so that
// secure headers and rate limiting use the correct client IP.
app.set('trust proxy', 1);

// Secure HTTP headers (Helmet)
app.use(helmet(helmetOptions));

// Cross-Origin Resource Sharing restricted to the configured frontend origins
app.use(cors(corsOptionsDelegate));
// CORS configuration
app.use(
cors({
origin: env.CORS_ORIGIN,
credentials: true,
}),
);

// Rate limiting
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // Limit each IP to 100 requests per windowMs
windowMs: env.RATE_LIMIT_WINDOW_MS,
max: env.RATE_LIMIT_MAX_REQUESTS,
standardHeaders: true,
legacyHeaders: false,
});
Expand Down
3 changes: 2 additions & 1 deletion src/config/database.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import mongoose from 'mongoose';
import logger from './logger';
import env from './env';

export const connectDatabase = async (): Promise<void> => {
try {
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/swiftchain';
const mongoUri = env.MONGODB_URI;

await mongoose.connect(mongoUri);

Expand Down
5 changes: 3 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import app from './app';
import logger from './config/logger';
import env from './config/env';

const PORT = process.env.PORT || 3000;
const PORT = env.PORT;

const server = app.listen(PORT, () => {
logger.info(`🚀 Server running on port ${PORT} in ${process.env.NODE_ENV} mode`);
logger.info(`🚀 Server running on port ${PORT} in ${env.NODE_ENV} mode`);
logger.info(`📝 Health check: http://localhost:${PORT}/health`);
});

Expand Down
Loading