Skip to content

Commit

Permalink
Merge pull request #209 from pknu-wap/#203/feature/juno/user_profile_…
Browse files Browse the repository at this point in the history
…image
  • Loading branch information
ho-sick99 authored Aug 16, 2023
2 parents 186c72f + 872c911 commit 51a026e
Show file tree
Hide file tree
Showing 10 changed files with 523 additions and 96 deletions.
5 changes: 5 additions & 0 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const bodyParser = require('body-parser');
const dotenv = require("dotenv");
dotenv.config();
const { swaggerUi, specs } = require("./swagger/swagger"); // swagger
const path = require("path");
const imgsDir = path.join(__dirname, '..', 'imgs'); // path to save uploaded files

// 라우팅
const home = require("./src/routes/home");
Expand All @@ -16,6 +18,9 @@ const home = require("./src/routes/home");
app.use(express.json()) // 내장 body-parser
app.use(express.urlencoded({ extended: true }))

// set static folder
app.use('/imgs', express.static(imgsDir)); // folder destination

app.use("/", home);

app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(specs))
Expand Down
87 changes: 55 additions & 32 deletions server/bin/www.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,63 @@
"use strict";

const app = require("../app");
const models = require('../src/models/index.js');
const models = require("../src/models/index.js");
const PORT = process.env.PORT || 3000; // 포트
const fs = require("fs");
const { imgsDir } = require("../src/config/staticDirLoc");

const { auto } = require("../src/config/sequelizeAuto")

const oracledb = require("oracledb")
const { auto } = require("../src/config/sequelizeAuto");

const oracledb = require("oracledb");

app.listen(PORT, async () => {
if (process.env.NODE_ENV == 'development') { // 현재 개발 환경이라면
oracledb.initOracleClient({ libDir: process.env.DB_ORACLEHOME }); // 개발 머신에 따라 oracle client 경로 수동 설정
}

try {
await models.sequelize.sync({force: false, alter: false});
} catch (err) {
console.log('DB 연결 중 오류 발생: ', err);
process.exit();
}

// Find all users
const users = await models.User.findAll();
console.log(users.every(user => user instanceof models.User)); // true
console.log("All users:", JSON.stringify(users, null, 2));
console.log("All medicines:", JSON.stringify(await models.Medicine.findAll(), null, 2));
console.log("All likes:", JSON.stringify(await models.Like.findAll(), null, 2));
console.log("All comments:", JSON.stringify(await models.Comment.findAll(), null, 2));
console.log("All favorite medicines:", JSON.stringify(await models.FavoriteMedicine.findAll(), null, 2));

// // model auto generation test
// auto.run((err) => {
// if (err) throw err;
// console.log(auto.tables); // 생성된 모델 확인
// });

console.log(`Server running on port ${PORT}`);
});
if (process.env.NODE_ENV == "development") {
// 현재 개발 환경이라면
oracledb.initOracleClient({ libDir: process.env.DB_ORACLEHOME }); // 개발 머신에 따라 oracle client 경로 수동 설정
}

try {
await models.sequelize.sync({ force: false, alter: false });
} catch (err) {
console.log("DB 연결 중 오류 발생: ", err);
process.exit();
}

// Find all users
const users = await models.User.findAll();
console.log(users.every((user) => user instanceof models.User)); // true
console.log("All users:", JSON.stringify(users, null, 2));
console.log(
"All medicines:",
JSON.stringify(await models.Medicine.findAll(), null, 2)
);
console.log(
"All likes:",
JSON.stringify(await models.Like.findAll(), null, 2)
);
console.log(
"All comments:",
JSON.stringify(await models.Comment.findAll(), null, 2)
);
console.log(
"All favorite medicines:",
JSON.stringify(await models.FavoriteMedicine.findAll(), null, 2)
);

// // model auto generation test
// auto.run((err) => {
// if (err) throw err;
// console.log(auto.tables); // 생성된 모델 확인
// });

if (!fs.existsSync(imgsDir)) { // path doesn't exist
try {
fs.mkdirSync(imgsDir); // create directory
console.log("Directory created successfully.");
} catch (error) {
console.error("Error creating directory:", error);
}
}

console.log(`Server running on port ${PORT}`);
});
Loading

0 comments on commit 51a026e

Please sign in to comment.