Skip to content

Commit 6e5a656

Browse files
committed
optimization wip
1 parent 6a78353 commit 6e5a656

File tree

11 files changed

+42
-17
lines changed

11 files changed

+42
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ You can clone the full repo and keep only the packages you need in your monorepo
1010
- [React](https://reactjs.org/), [NestJs](https://nestjs.com/), [ExpressJS](https://expressjs.com/), [NestJS](https://nestjs.com/)
1111
- 100% [Typescript](https://www.typescriptlang.org/)
1212
- [Prettier](https://prettier.io/) and [Eslint](https://eslint.org/) setup alongside `pre-commit` hook.
13-
- [Mui v6](https://mui.com/) alongside theme change preconfigured.
13+
- [Mui v7](https://mui.com/) alongside theme change preconfigured.
1414
- [Dockerize](https://docs.docker.com/) images
1515
- Github Actions to build apps and publish their docker images
1616

apps/express-server/src/app-constants/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

apps/express-server/src/app.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import express, {
44
type Response
55
} from 'express';
66
import cors from 'cors';
7-
import { ENV_VARS } from '@/app-constants';
7+
import { ENV_CONFIG } from '@/constants';
88
import { requestLogger } from '@/middleware';
9-
import * as Routes from '@/routes';
9+
import { routesList } from '@/routes';
1010

1111
const app: Express = express();
1212

@@ -17,10 +17,15 @@ app.use(cors());
1717
app.use(requestLogger);
1818

1919
app.get('/', (_: Request, response: Response) => {
20-
response.status(200).send(`ENV: ${ENV_VARS.env} - Api is up & running!!!`);
20+
response.status(200).json({
21+
env: ENV_CONFIG.env,
22+
message: 'Api is up & running!!!'
23+
});
2124
});
2225

23-
app.use('/api/auth', Routes.authRouter);
26+
routesList.forEach(route => {
27+
app.use(route.path, route.router);
28+
});
2429

2530
/* 404 Handler - To be written at last */
2631
app.get('*', (req: Request, response: Response) => {

apps/express-server/src/app-constants/env_vars.ts renamed to apps/express-server/src/constants/environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
const env = process.env;
77

8-
export const ENV_VARS = Object.freeze({
8+
export const ENV_CONFIG = Object.freeze({
99
env: env.NODE_ENV ?? 'development',
1010
port: env.PORT ?? 8000
1111
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './environment';

apps/express-server/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
import 'dotenv/config';
1818
import os from 'os';
1919
import { createServer } from 'node:http';
20-
import { ENV_VARS } from '@/app-constants';
20+
import { ENV_CONFIG } from '@/constants';
2121
import { winstonLogger } from '@/middleware';
2222
import app from './app';
2323

2424
const hostName = os.hostname();
25-
const port = ENV_VARS.port;
25+
const { port, env } = ENV_CONFIG;
2626

2727
function bootstrap() {
2828
/* DB Connection Logic */
@@ -39,7 +39,7 @@ function bootstrap() {
3939

4040
server.listen(port, () => {
4141
winstonLogger.info(
42-
`[ ⚡️ ${hostName} ⚡️ ] - Server running on port ${port}`
42+
`[ ⚡️ ${hostName}@${env} ⚡️ ] - Server running on port ${port}`
4343
);
4444
});
4545
}

apps/express-server/src/middleware/winston-logger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/restrict-template-expressions */
22

33
import { createLogger, addColors, format, transports } from 'winston';
4-
import { ENV_VARS } from '@/app-constants';
4+
import { ENV_CONFIG } from '@/constants';
55

66
const { combine, timestamp, printf } = format;
77

@@ -72,7 +72,7 @@ addColors(customLevels.colors);
7272
* `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
7373
*/
7474

75-
if (ENV_VARS.env !== 'production') {
75+
if (ENV_CONFIG.env !== 'production') {
7676
winstonLogger.add(
7777
new transports.Console({ format: format.colorize({ all: true }) })
7878
);

apps/express-server/src/routes/auth/controller.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import type * as AuthTypes from './types';
55
const authRouter = Router();
66

77
authRouter.get('/test', function printHello(_, res: Response) {
8-
return res.status(200).send('Hello World !!')
9-
.end();
8+
return res.status(200).send('Hello World !!').end();
109
});
1110

1211
/* Login user */
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
import { type Router} from 'express';
12
import { authRouter } from './auth/controller';
23

3-
export { authRouter };
4+
type RouteInfo = {
5+
path: string;
6+
router: Router;
7+
}
8+
9+
function generatePrefix(routeName: string) {
10+
return `/api${routeName}`;
11+
}
12+
13+
const routesList: RouteInfo[] = [
14+
{
15+
path: generatePrefix('/auth'),
16+
router: authRouter
17+
}
18+
];
19+
20+
export { routesList };

apps/next-client/src/theme/palette.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*
44
* https://zenoo.github.io/mui-theme-creator/
55
* https://m2.material.io/inline-tools/color/
6+
* https://bareynol.github.io/mui-theme-creator/
67
*/
78

89
export const LightThemePalette = {

apps/react-client/src/assets/styles/palette.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/**
2-
* Dark mode with MUI.
3-
* https://mui.com/material-ui/customization/dark-mode/
2+
* Check out these resources for building theme -
3+
*
4+
* https://zenoo.github.io/mui-theme-creator/
5+
* https://m2.material.io/inline-tools/color/
6+
* https://bareynol.github.io/mui-theme-creator/
47
*/
58

69
export const LightThemePalette = {

0 commit comments

Comments
 (0)