Skip to content

Commit 3a5046e

Browse files
initialize application module and package
1 parent 276b75e commit 3a5046e

File tree

6 files changed

+53
-4
lines changed

6 files changed

+53
-4
lines changed

.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Database Configuration
44
DB_HOST=localhost
5-
DB_PORT=5432
5+
DB_PORT=3306
66
DB_USERNAME=root
77
DB_PASSWORD=""
88
DB_NAME=aivisiontext_db
@@ -26,3 +26,4 @@ SMTP_PORT=587
2626
2727
SMTP_PASSWORD=your_email_password
2828

29+
SSL=true

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"dependencies": {
2323
"@nestjs/axios": "^3.0.0",
2424
"@nestjs/common": "^10.0.0",
25+
"@nestjs/config": "^3.0.1",
2526
"@nestjs/core": "^10.0.0",
2627
"@nestjs/jwt": "^10.1.1",
2728
"@nestjs/platform-express": "^10.0.0",
@@ -37,6 +38,7 @@
3738
"express-validator": "^7.0.1",
3839
"jsonwebtoken": "^9.0.2",
3940
"multer": "^1.4.5-lts.1",
41+
"mysql2": "^3.6.1",
4042
"pdf-parse": "^1.1.1",
4143
"reflect-metadata": "^0.1.13",
4244
"rxjs": "^7.8.1",
@@ -48,6 +50,7 @@
4850
"@nestjs/schematics": "^10.0.0",
4951
"@nestjs/testing": "^10.0.0",
5052
"@types/body-parser": "^1.19.2",
53+
"@types/compression": "^1.7.3",
5154
"@types/cookie-parser": "^1.4.4",
5255
"@types/express": "^4.17.17",
5356
"@types/jest": "^29.5.2",

src/app.module.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
import { Module } from '@nestjs/common';
22
import { AppController } from './app.controller';
33
import { AppService } from './app.service';
4+
import { TypeOrmModule } from '@nestjs/typeorm';
5+
import { ConfigModule } from '@nestjs/config';
6+
import configuration from 'src/config/config';
47

58
@Module({
6-
imports: [],
9+
imports: [
10+
ConfigModule.forRoot({
11+
envFilePath: '.env',
12+
isGlobal: true,
13+
load: [configuration],
14+
}),
15+
TypeOrmModule.forRoot({
16+
type: 'mysql',
17+
host: process.env.DB_HOST,
18+
port: parseInt(process.env.DB_PORT, 3306) || 3306,
19+
username: process.env.DB_USERNAME,
20+
password: process.env.DB_PASSWORD,
21+
database: process.env.DB_NAME,
22+
entities: [],
23+
synchronize: true,
24+
}),
25+
],
726
controllers: [AppController],
827
providers: [AppService],
928
})

src/config/global.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default () => ({
2+
port: parseInt(process.env.PORT, 10) || 3000,
3+
database: {
4+
host: process.env.DB_HOST,
5+
user: process.env.DB_USERNAME,
6+
password: process.env.DB_PASSWORD,
7+
name: process.env.DB_NAME,
8+
port: parseInt(process.env.DB_PORT, 10) || 5432,
9+
},
10+
});

src/main.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,31 @@ import { NestFactory } from '@nestjs/core';
22
import { AppModule } from './app.module';
33
import * as cookieParser from 'cookie-parser';
44
import * as bodyParser from 'body-parser';
5+
import * as compression from 'compression';
6+
import fs from 'fs';
7+
import path from 'path';
58

69
async function bootstrap() {
7-
const app = await NestFactory.create(AppModule);
10+
const ssl = process.env.SSL === 'true';
11+
let httpsOptions = null;
12+
if (ssl) {
13+
const keyPath = process.env.SSL_KEY_PATH || '';
14+
const certPath = process.env.SSL_CERT_PATH || '';
15+
httpsOptions = {
16+
key: fs.readFileSync(path.join(__dirname, keyPath)),
17+
cert: fs.readFileSync(path.join(__dirname, certPath)),
18+
};
19+
}
20+
21+
const app = await NestFactory.create(AppModule, { httpsOptions });
822

9-
app.use(cookieParser());
1023
app.setGlobalPrefix('api');
1124
app.use(bodyParser.json({ limit: '10000mb' }));
1225
app.use(bodyParser.urlencoded({ limit: '9000mb', extended: true }));
1326

27+
app.use(cookieParser());
28+
app.use(compression());
29+
1430
app.enableCors({
1531
origin: ['https://localhost:4200', 'http://localhost:4200'],
1632
allowedHeaders: [

ssl-secret.key

Whitespace-only changes.

0 commit comments

Comments
 (0)