-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DB 연결 Loader 파일로 분리 port listen 역할 server.ts로 분리 - 테스트 코드에서 app import 해야하는데 이때 서버가 실행되지 않도록 분리
- Loading branch information
Showing
9 changed files
with
66 additions
and
57 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
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
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,17 @@ | ||
import * as dotenv from "dotenv"; | ||
import mongoose from "mongoose"; | ||
|
||
dotenv.config(); | ||
|
||
export default function connectMongoDB() { | ||
mongoose.connect( | ||
`mongodb+srv://${process.env.MONGODB_ID}:${process.env.MONGODB_PASSWORD}@cluster0.a7vmgdw.mongodb.net/database0?`, | ||
(err) => { | ||
if (err) { | ||
console.log(err); | ||
} else { | ||
console.log("mongoDB is connected..."); | ||
} | ||
} | ||
); | ||
} |
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,16 @@ | ||
import * as dotenv from "dotenv"; | ||
import "reflect-metadata"; | ||
import { DataSource } from "typeorm"; | ||
|
||
dotenv.config(); | ||
const myDataSource = new DataSource({ | ||
type: "mysql", | ||
host: process.env.TYPEORM_HOST || "", | ||
port: Number(process.env.TYPEORM_PORT), | ||
username: process.env.TYPEORM_USERNAME || "", | ||
password: process.env.TYPEORM_PASSWORD || "", | ||
database: process.env.TYPEORM_DATABASE || "", | ||
entities: [`${__dirname}/../**/*.Model{.ts,.js}`], | ||
}); | ||
|
||
export default myDataSource; |
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,18 @@ | ||
import * as redis from "redis"; | ||
|
||
const redisClient = redis.createClient({ | ||
url: `redis://@${process.env.REDIS_HOST}:${process.env.REDIS_PORT}/0`, | ||
legacyMode: true, | ||
}); | ||
|
||
redisClient.on("connect", () => { | ||
console.info("Redis connected!"); | ||
}); | ||
redisClient.on("error", (err) => { | ||
console.error("Redis Client Error", err); | ||
}); | ||
|
||
redisClient.connect(); | ||
const redisCli = redisClient.v4; | ||
|
||
export default redisCli; |
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
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,11 @@ | ||
import app from "./app"; | ||
import myDataSource from "./Loader/MySQL.Loader"; | ||
import connectMongoDB from "./Loader/Mongo.Loader"; | ||
|
||
myDataSource.initialize().then(() => { | ||
console.log("Data Source has been initialized!"); | ||
}); | ||
|
||
connectMongoDB(); | ||
|
||
app.listen(process.env.PORT); |