Skip to content

Commit

Permalink
build: node 20.6.0 내장 .env 파일 기능 사용 (#78)
Browse files Browse the repository at this point in the history
* refactor: 내보내기 전 db를 미리 초기화

* refactor: 내보내기 전 redis를 초기화

* feat: `/openapi.json` 경로 추가

* fix: 업데이트 빈도를 1일 1회로 낮춤
  • Loading branch information
scarf005 authored Nov 8, 2023
1 parent be721b9 commit 57f2702
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
32 changes: 17 additions & 15 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ app.use(express.json());
app.use(morgan("dev"));

app.use("/api", testRouter);
app.use("/openapi", swaggerUi.serve, swaggerUi.setup(openApiDocument));

db.sequelize
.sync({
force: false, //임시
})
.then(() => {
console.log("connected");
})
.catch((err) => {
console.error(err);
});
const swaggerUrl = "/openapi.json";
app.get(swaggerUrl, (_req, res) => res.json(openApiDocument));
app.use(
"/openapi",
swaggerUi.serveFiles(undefined, { swaggerUrl }),
swaggerUi.setup(undefined, {
swaggerUrl,
swaggerOptions: {
persistAuthorization: true,
withCredentials: true,
},
}),
);

// 인증 불필요 라우터
const c = initContract();
Expand Down Expand Up @@ -72,11 +74,11 @@ createExpressEndpoints(
//리뷰 작성(맛집 api 이후 수정 필요)
createExpressEndpoints(reviewContract, reviewRouter, app, jwtMiddleware);

app.listen(3000, () => {
app.listen(3000, async () => {
console.log("Server On");
schedule.scheduleJob("0 * * * * *", function () {
dbScheduler();
});

await dbScheduler();
schedule.scheduleJob("0 0 0 * * *", dbScheduler);
});

/*
Expand Down
7 changes: 7 additions & 0 deletions src/db/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import { dbSchema } from "../../env";
const config = dbSchema.parse(process.env);
const sequelize = new Sequelize(config);

await sequelize
.sync({
force: false, //임시
})
.then(() => console.log("sequelize is connected"))
.catch((err) => console.error("sequelize error:", err));

const db = { sequelize, User, Review, Restaurant };

db.User.initUser(sequelize);
Expand Down
16 changes: 4 additions & 12 deletions src/redis.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import { createClient } from "redis";

//default local 127.0.0.1:6379
const redisClient = createClient();

await redisClient.connect();
console.log("redis is connected");

redisClient.on("ready", () => {
console.log("redis is ready");
});

redisClient.on("error", (error) => {
console.log(error);
});
const redisClient = await createClient()
.on("ready", () => console.log("redis is ready"))
.on("error", (error) => console.log("redis error:", error))
.connect();

export default redisClient;

0 comments on commit 57f2702

Please sign in to comment.