Skip to content

Commit

Permalink
Merge pull request #218 from pknu-wap/server_main
Browse files Browse the repository at this point in the history
Server main 병합
  • Loading branch information
ho-sick99 authored Aug 22, 2023
2 parents 91535fa + ffe8359 commit 2023746
Show file tree
Hide file tree
Showing 44 changed files with 5,311 additions and 3 deletions.
Binary file added .DS_Store
Binary file not shown.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*.class

# Generated files
bin/
gen/
out/
# Uncomment the following line in case you need and you don't have the release build type files in your app
Expand Down Expand Up @@ -82,4 +81,7 @@ lint/intermediates/
lint/generated/
lint/outputs/
lint/tmp/
# lint/reports/
# lint/reports/

# Static folder
imgs/
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
// IntelliSense를 사용하여 가능한 특성에 대해 알아보세요.
// 기존 특성에 대한 설명을 보려면 가리킵니다.
// 자세한 내용을 보려면 https://go.microsoft.com/fwlink/?linkid=830387을(를) 방문하세요.
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "서버 실행 - 기본값",
"skipFiles": [
"<node_internals>/**"
],
"cwd": "${workspaceFolder}/server",
"program": "${workspaceFolder}/server/bin/www.js"
},

{
"type": "node",
"request": "launch",
"name": "서버 실행 - 재완 맥북",
"skipFiles": [
"<node_internals>/**"
],
"cwd": "${workspaceFolder}/server",
"program": "${workspaceFolder}/server/bin/www.js",
"runtimeExecutable": "${env:HOME}/.nvm/versions/node/v14.21.3/bin/node"
}
]
}
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added server/.DS_Store
Binary file not shown.
141 changes: 141 additions & 0 deletions server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

### Node Patch ###
# Serverless Webpack directories
.webpack/

# Optional stylelint cache

# SvelteKit build / generate output
.svelte-kit

# End of https://www.toptal.com/developers/gitignore/api/node
19 changes: 19 additions & 0 deletions server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

```
server
├─ .gitignore
├─ app.js
├─ bin
│ └─ www.js
├─ migrations
├─ package-lock.json
├─ package.json
├─ seeders
└─ src
├─ config
├─ controller
├─ routes
├─ models
└─ service
```
28 changes: 28 additions & 0 deletions server/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"use strict";

// 모듈
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const dotenv = require("dotenv");
dotenv.config();
const { swaggerUi, specs } = require("./swagger/swagger"); // swagger
const path = require("path");
const { imgsDir } = require("./src/config/staticDirLoc"); // path to save uploaded files

// 라우팅
const home = require("./src/routes/home");

// 미들웨어
// app.use(bodyParser.json());
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));

module.exports = app;
63 changes: 63 additions & 0 deletions server/bin/www.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"use strict";

const app = require("../app");
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");

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); // 생성된 모델 확인
// });

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 2023746

Please sign in to comment.