Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
paperhsiaooo committed Jun 11, 2023
2 parents 36c7d5c + 588e054 commit f36f6bf
Show file tree
Hide file tree
Showing 88 changed files with 6,664 additions and 48 deletions.
10 changes: 9 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
PORT=YOUR_BACKEND_SERVICE_PORT
NODE_ENV=PROJECT_LAUNCH_ENVEIRONMENT
PORT=YOUR_BACKEND_SERVICE_PORT
JWT_SECRET=SECRET_FOR_JWT
ORIGIN=ORIGIN
AWS_ACCESS_KEY_ID=AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY=AWS_SECRET_ACCESS_KEY
AWS_REGION=AWS_REGION
AWS_BUCKET_NAME=AWS_BUCKET_NAME
CLOUDFRONT_AVATAR_BUCKET_URL=CLOUDFRONT_AVATAR_BUCKET_URL
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
16 changes: 16 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
env: {
node: true,
commonjs: true,
es2021: true,
jest: true
},
extends: ['eslint:recommended', 'eslint-config-prettier'],
overrides: [],
parserOptions: {
ecmaVersion: 'latest'
},
rules: {
'no-unused-vars': false
}
}
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
# Edit at https://www.toptal.com/developers/gitignore?templates=windows,visualstudiocode

### VisualStudioCode ###
.vscode/*
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/*.env
*.code-workspace
*.env

Expand Down Expand Up @@ -61,3 +57,5 @@ react/package-lock.json

backend.exe
/node_modules

uploads
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"semi": false,
"tabWidth": 2,
"printWidth": 100,
"singleQuote": true,
"trailingComma": "none",
"jsxBracketSameLine": true
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.format.enable": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
}
122 changes: 122 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Changelog

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## 1.1.0 (2023-06-11)


### Features

* add user register API. ([cec7e1b](https://github.com/HSNM2/backend-nodejs/commit/cec7e1b3c3658809c3d011a04ac560725e773a3b))
* add user register API. ([ce1b360](https://github.com/HSNM2/backend-nodejs/commit/ce1b360ff696616688fb162f2a3e30f0017b602b))
* courseProvider 需要有 token 驗證 ([367640d](https://github.com/HSNM2/backend-nodejs/commit/367640d11df36d45438d75a63d80f8aa888d3f8d))
* lesson add video path ([bc5b4c2](https://github.com/HSNM2/backend-nodejs/commit/bc5b4c214cff8e8d308ed0ce5b524a15870d0006))
* users table 新增 identity column ([16eea56](https://github.com/HSNM2/backend-nodejs/commit/16eea566443589bfa5f402ff6b6f6ab804db4212))
* 修改 取得收藏為獨立API ([22c0b45](https://github.com/HSNM2/backend-nodejs/commit/22c0b45c9d600629524004e41de385b965d44888))
* 修改取得課程列表 ([de5257a](https://github.com/HSNM2/backend-nodejs/commit/de5257a8db5b09cf67d0bea969805f44d65414e1))
* 修正 /get profile 的資料欄位 ([3b94355](https://github.com/HSNM2/backend-nodejs/commit/3b9435518597860924b2c492773f197899663445))
* 修正 alias ([27b2ab8](https://github.com/HSNM2/backend-nodejs/commit/27b2ab8d0c813fa772d49a83607189a185aa14a2))
* 修正 origin ([1d02d1c](https://github.com/HSNM2/backend-nodejs/commit/1d02d1c214220ad11e1521e95229aac2d44a0b16))
* 修正 post /user/profile 的欄位 ([0de1c54](https://github.com/HSNM2/backend-nodejs/commit/0de1c543c8724912daeb663b0f9824e799c3755c))
* 修正 profile 獲取資訊 ([e6fed53](https://github.com/HSNM2/backend-nodejs/commit/e6fed53b273d2b58c57cbf78eb0779a9cce9ddfc))
* 修正 提問/回覆留言 ([3b17ade](https://github.com/HSNM2/backend-nodejs/commit/3b17ade86befffc619d9af6d2f5bd9348e8b2823))
* 修正 新增/刪除收藏課程 ([4a9f3dd](https://github.com/HSNM2/backend-nodejs/commit/4a9f3dd2da55c071e8f89a1ec946c5b90339770a))
* 初始化專案 ([00bc7c5](https://github.com/HSNM2/backend-nodejs/commit/00bc7c57ab9449e5694e727336acd9ca50544034))
* 取得單一課程資料 api ([ca2881d](https://github.com/HSNM2/backend-nodejs/commit/ca2881de8a6c14fef59d3293eeca16646933bf1f))
* 取得課程介面的課程資訊 ([65d8708](https://github.com/HSNM2/backend-nodejs/commit/65d8708cf1fb8906abc16875d53c4828b84cac6e))
* 安裝 module-alias ([1592334](https://github.com/HSNM2/backend-nodejs/commit/15923345276dee149b013b24044b178a9fbbc785))
* 建立 user 和 course 的關聯表 ([56413e2](https://github.com/HSNM2/backend-nodejs/commit/56413e2ef12b5baa50a6651bccf7453a83594d4e))
* 建立單元 ([a333b3b](https://github.com/HSNM2/backend-nodejs/commit/a333b3bd7d362e19fe9e7113edb644780a14f0ad))
* 建立課程提供者所需的 router、controllers 與 models ([bf74aa7](https://github.com/HSNM2/backend-nodejs/commit/bf74aa7e483bdd005669aa9a1486d55bc7a72629))
* 建立需要的 migrations ([749010b](https://github.com/HSNM2/backend-nodejs/commit/749010b614001a30cd4b7fa7f3e35d4bf4d057b0))
* 忽略 upload folder ([95fdd40](https://github.com/HSNM2/backend-nodejs/commit/95fdd404012f73dd91cd21acc29aa48ce239b37f))
* 新增 chapter 的 CRUD ([59631b4](https://github.com/HSNM2/backend-nodejs/commit/59631b44636379df50725ee36da35d41e5ec4b57))
* 新增 chapter 與 lesson 防呆 ([28af0ff](https://github.com/HSNM2/backend-nodejs/commit/28af0fff5021bc13ae37a85548ba54419b395820))
* 新增 DB 大頭貼欄位 ([262c8e3](https://github.com/HSNM2/backend-nodejs/commit/262c8e39934f1ad1f8a06aa621d1730206fa1731))
* 新增 db 相關指令與配置 ([223bcc0](https://github.com/HSNM2/backend-nodejs/commit/223bcc094c0f16fa3550e56bf0420506b4a69b56))
* 新增 db 相關指令與配置 ([37e8537](https://github.com/HSNM2/backend-nodejs/commit/37e8537f12bc0ffddb8983d20fb0d8da69ed1873))
* 新增 db 相關指令與配置 ([c514b27](https://github.com/HSNM2/backend-nodejs/commit/c514b27bfbb79714794e2774a778d4663459af29))
* 新增 delete avatar 與 update image ([b58de6f](https://github.com/HSNM2/backend-nodejs/commit/b58de6f15cf4839fdcba07b0d369b45c21fdc768))
* 新增 delete 問題類別 api ([93c4299](https://github.com/HSNM2/backend-nodejs/commit/93c42999d0187f213823ebd82ef6aee906a0e5c7))
* 新增 error template for chapter. ([af45caa](https://github.com/HSNM2/backend-nodejs/commit/af45caab229d266426f8c01423dbbcddbf7bfc6a))
* 新增 faq 與 question 的 middleware ([15b3ce6](https://github.com/HSNM2/backend-nodejs/commit/15b3ce6d67f5212978ef2fda8ba7115b940a2051))
* 新增 faq 與 question 的 router ([4cb5c81](https://github.com/HSNM2/backend-nodejs/commit/4cb5c81b991c3b98da784575514ab7ee0eedce37))
* 新增 format.js ([6074b21](https://github.com/HSNM2/backend-nodejs/commit/6074b214d6ebdc079a1ffe353a99d7d67199ea95))
* 新增 get 取得問題列表資訊 api ([8f7002a](https://github.com/HSNM2/backend-nodejs/commit/8f7002a89fd503533d6d8d1026fb2ada6011ed48))
* 新增 hashId 當作 user 編號 ([4634513](https://github.com/HSNM2/backend-nodejs/commit/4634513770ba678c702137fed03b79bbc1910c3b))
* 新增 jwt 流程 ([74d75a7](https://github.com/HSNM2/backend-nodejs/commit/74d75a7ececa6945c78cf58f3349830c987d601a))
* 新增 multer middle 在 /profile/pic/upload ([f017cb2](https://github.com/HSNM2/backend-nodejs/commit/f017cb28ed45cc31e15b8e0d9be7865e6c04ed72))
* 新增 patch 問題類別 api ([9b93ce6](https://github.com/HSNM2/backend-nodejs/commit/9b93ce6fb32dfe9c85d435fb38da01b68d5e7874))
* 新增 post 問題類別 api ([d4db993](https://github.com/HSNM2/backend-nodejs/commit/d4db9934f642990183737e92654e74b61b4e363f))
* 新增 question 的 router api ([be4ce64](https://github.com/HSNM2/backend-nodejs/commit/be4ce6417bcbb85bfcbbbc8ac7de4d609b49ccfc))
* 新增 register 的流程 ([7a754d1](https://github.com/HSNM2/backend-nodejs/commit/7a754d194c12c4f23c7fbc6a3e5865329bee7943))
* 新增 verifyCourseProvide 的 middle ([02ed482](https://github.com/HSNM2/backend-nodejs/commit/02ed4829d4882821a1a3007eb91e157b0c6295a8))
* 新增 課程列表 page 功能 ([100e15c](https://github.com/HSNM2/backend-nodejs/commit/100e15c25d9b5785d437819ad5765d23e415ca69))
* 新增 課程持有確認 ([ddd6c50](https://github.com/HSNM2/backend-nodejs/commit/ddd6c500c1652077338513af0dfa8c5a6ffe8cbf))
* 新增 金流加密所需參數 ([c514642](https://github.com/HSNM2/backend-nodejs/commit/c514642090e41aecd1efd846fed3fa0fd0d8bbbd))
* 新增 金流結帳完成,增加課程購買人數 ([50bc2d4](https://github.com/HSNM2/backend-nodejs/commit/50bc2d47ddf108061a6e52991263103690dc82c4))
* 新增「更新 profile」API ([0eb07da](https://github.com/HSNM2/backend-nodejs/commit/0eb07da4243215329cb41c38a270c114fb6201fe))
* 新增上傳大頭貼流程 ([cb9a05b](https://github.com/HSNM2/backend-nodejs/commit/cb9a05b47fe72fc9ead68dbf38e871c716f06784))
* 新增修改課程資訊 ([b24bd70](https://github.com/HSNM2/backend-nodejs/commit/b24bd70555ecb54f4b2285f109af36950dbdb887))
* 新增刪除流程 ([8893dfe](https://github.com/HSNM2/backend-nodejs/commit/8893dfe6d94d8db1f4ec76e058446910f84a557c))
* 新增前台獲取 lesson 有 videoPath ([e630183](https://github.com/HSNM2/backend-nodejs/commit/e6301837614cdeb58f2b958d2f355bd70feb320f))
* 新增創建 course api 流程 ([36cbd0b](https://github.com/HSNM2/backend-nodejs/commit/36cbd0bd9a50ad3b55c2342fb175ce57c73d1935))
* 新增取得課程列表 ([ef90374](https://github.com/HSNM2/backend-nodejs/commit/ef903744f67d7e582233db3dd6c1b197fb1ca9a6))
* 新增取得課程詳細資訊-課前詢問、常見問題、課程評價 ([ace5460](https://github.com/HSNM2/backend-nodejs/commit/ace5460029e6ab02839d050511d170c13bd4c359))
* 新增單元刪除流程 ([d2f5d5c](https://github.com/HSNM2/backend-nodejs/commit/d2f5d5cae59d99a4d4018b8c41964125ac176c55))
* 新增在 user/profile 時可以獲取 avatarImagePage ([f1f4d05](https://github.com/HSNM2/backend-nodejs/commit/f1f4d05e9f126741f10666d2ab0b851f44ef9467))
* 新增本地上傳大頭貼功能 ([d538ebe](https://github.com/HSNM2/backend-nodejs/commit/d538ebe3d83efe93b4383892f8f0903097f1b73d))
* 新增本地上傳大頭貼功能 ([0eecd6a](https://github.com/HSNM2/backend-nodejs/commit/0eecd6a98dd4224e86cd1337a356c2f1a682d54e))
* 新增獲取會員資料功能 ([8c8ffeb](https://github.com/HSNM2/backend-nodejs/commit/8c8ffeb8975cf6973d9f6bd8505b4b7cf4fec531))
* 新增產品列表 ([f2f8add](https://github.com/HSNM2/backend-nodejs/commit/f2f8addf8fe908804ec7b45d5100f42e39797ff4))
* 新增藍新金流與購物流程API,order 與 order detail 表 ([a080259](https://github.com/HSNM2/backend-nodejs/commit/a08025987ca388db37a98d56eac20e7ff88934ae))
* 新增課程「上架/下架」流程 ([27b3552](https://github.com/HSNM2/backend-nodejs/commit/27b3552133258eeda9d96dfb37e6ad4bbedaac29))
* 新增課程收藏與刪除收藏 ([fbfe38a](https://github.com/HSNM2/backend-nodejs/commit/fbfe38a1d855c79c3392c59ff0e41f56bd1cd510))
* 新增課程詳細資訊-大綱與章節 ([601cc49](https://github.com/HSNM2/backend-nodejs/commit/601cc4990b58f28b14e949cc219adf7954d1efe4))
* 新增購物車列表 ([ce0fab9](https://github.com/HSNM2/backend-nodejs/commit/ce0fab9c0afcdc1228dc5319dc0cbc70af1c8a3f))
* 新增部分 router 與對應 controller ([45c1401](https://github.com/HSNM2/backend-nodejs/commit/45c14017f79962ab87735814c666b117862585ce))
* 移除尚未刪除的 router ([b5ac17b](https://github.com/HSNM2/backend-nodejs/commit/b5ac17bc34066b6d7d0524bada1028f40e42963a))
* 金流增加姓名參數做混淆 ([49dc1ee](https://github.com/HSNM2/backend-nodejs/commit/49dc1ee30c51c08c77002d8394574774aa8f2b48))


### Bug Fixes

* addColumn faq schema down 排序調整 ([1c32e5e](https://github.com/HSNM2/backend-nodejs/commit/1c32e5e682f132f668cd443ec6c29f4b9c29e76a))
* allow column of type in course table is null ([8817b71](https://github.com/HSNM2/backend-nodejs/commit/8817b71fdacf457061d2a67a48c09ce371c665ad))
* phone 進入 db 格式錯誤問題 ([c29d8d7](https://github.com/HSNM2/backend-nodejs/commit/c29d8d79e028da315b77607910ee2c0b1f35b356))
* uploadMiddleware 依照不同環境切換 storage 功能 ([5364639](https://github.com/HSNM2/backend-nodejs/commit/5364639ef5e4f1d1e4ea4b23ebf9eb87ac11c37f))
* 修改 createOrder api 取得總價 ([08b0088](https://github.com/HSNM2/backend-nodejs/commit/08b00885da33a7f7103b5df36a8eb3a0dbf5b5f1))
* 修改 faq schema 欄位,前台取得課程資料 ([9b46d28](https://github.com/HSNM2/backend-nodejs/commit/9b46d28536e411da875202928e0d81c02a542d3c))
* 修改 創建訂單參數 ([f2c269a](https://github.com/HSNM2/backend-nodejs/commit/f2c269add7e46e576a65d939cd69ce7805437a05))
* 修改 整合format ([c47a8d3](https://github.com/HSNM2/backend-nodejs/commit/c47a8d318007d70a5131e47b87ed73ff93bfa83a))
* 修改 課前詢問、評分回傳資訊 ([dd680b5](https://github.com/HSNM2/backend-nodejs/commit/dd680b5c832af5fe3fd896f0ce675b3985d9ffdf))
* 修正 courseProvider 的名稱為 courseProviderRouter ([39d1ae2](https://github.com/HSNM2/backend-nodejs/commit/39d1ae2b85f6fa1f5212c36aa2bd39d808d7b6e7))
* 修正 env property name ([09fde7d](https://github.com/HSNM2/backend-nodejs/commit/09fde7d361a4ef7deb43e137a7bbc32de17d53e1))
* 修正 faq 與 question 的 response 內容 ([f6db765](https://github.com/HSNM2/backend-nodejs/commit/f6db765cd0576d30dc54a4a53b39e90d9b6d5eaf))
* 修正 identityMapping 錯誤的 property ([88a5d25](https://github.com/HSNM2/backend-nodejs/commit/88a5d2521ed50baa205d144139f8d630dbfd541c))
* 修正 lesson 多餘的 sql 指令 ([73e1ffb](https://github.com/HSNM2/backend-nodejs/commit/73e1ffb200f86e6c1e31a3805eb9bb60c66c2ddf))
* 修正 local 儲存 avatar 的 path ([c3d6ec5](https://github.com/HSNM2/backend-nodejs/commit/c3d6ec5da4f6cdeddb753ae840440b9c03f5cfec))
* 修正 multer.single 接受的 name ([d83b01b](https://github.com/HSNM2/backend-nodejs/commit/d83b01bf816294f9c42a13bb969fd48bdb38ac47))
* 修正 profile patch 的 response 格式 ([57d7764](https://github.com/HSNM2/backend-nodejs/commit/57d77644736f3a7bae69e227415ccebe4dcb8a09))
* 修正 require file path ([1ea4a8a](https://github.com/HSNM2/backend-nodejs/commit/1ea4a8afaa76220c125786b729cc345c00d69152))
* 修正 user 和 course 的資料型別 ([dca95c9](https://github.com/HSNM2/backend-nodejs/commit/dca95c9072313c97aad9a48efc0675a948ae30a4))
* 修正 檔案遷移 ([26f81b1](https://github.com/HSNM2/backend-nodejs/commit/26f81b128d03bd9a5601cc684dbf180aacb51114))
* 修正 藍新金流notify接收資料 ([e187a2c](https://github.com/HSNM2/backend-nodejs/commit/e187a2c92460a5fa81979dca07e3915ea1a575ce))
* 修正「修改課程」的結果訊息 ([34f7f95](https://github.com/HSNM2/backend-nodejs/commit/34f7f9506d431138bc2a6bccb2a881e96c9eac1c))
* 修正下架修正的 DB 欄位名稱 ([ab308ca](https://github.com/HSNM2/backend-nodejs/commit/ab308ca56bcb24ef5bd44e957dc20cf945cb5d46))
* 修正使用者圖片路徑錯誤問題 ([2f1ebbf](https://github.com/HSNM2/backend-nodejs/commit/2f1ebbfab1230c44390c4c36c05cc39e16cbf0aa))
* 修正刪除課程 response 結構 ([96d507d](https://github.com/HSNM2/backend-nodejs/commit/96d507d83179df26663806b4bd851d7381afa26f))
* 修正單元上/下架的回傳訊息 ([7a5c5ef](https://github.com/HSNM2/backend-nodejs/commit/7a5c5efcdeff35beaa9dc1629c48de735da3d47b))
* 修正單元修改流程 ([f4a2c6b](https://github.com/HSNM2/backend-nodejs/commit/f4a2c6ba2e58b91aec5cc2cf7679be87af6a6cef))
* 修正是否為課程擁有者的判斷 ([5175994](https://github.com/HSNM2/backend-nodejs/commit/51759944be418088cc71e673eb26b2305e26277f))
* 修正檔案引入 path 方式 ([55c3281](https://github.com/HSNM2/backend-nodejs/commit/55c32811b0731df42cb8dafb5d0ec58e732379cc))
* 修正給予 env 方式 ([3be6aa9](https://github.com/HSNM2/backend-nodejs/commit/3be6aa9eb0c9a8aeedf71ca94518579fc2fa3649))
* 修正給予 env 方式 ([b90f9fb](https://github.com/HSNM2/backend-nodejs/commit/b90f9fb61c1199a784563e62f980976ad78dc3c0))
* 修正課程後台在獲取課程資訊時的資料內容 ([dad2502](https://github.com/HSNM2/backend-nodejs/commit/dad2502f32a4c84ae164c1c2f85f212668e9bae0))
* 修正部分課程 response 結構 ([8b3efc8](https://github.com/HSNM2/backend-nodejs/commit/8b3efc805023461acd2b8ed0517382988bfb7de6))
* 修正錯誤檔案名稱 ([6e018ab](https://github.com/HSNM2/backend-nodejs/commit/6e018ab721091f0d20491f44eaebf24cd01e29d9))
* 在註冊時,name 為 custom-${uuid} ([a0b1880](https://github.com/HSNM2/backend-nodejs/commit/a0b188090d8c945ceb5caf654035af3ba33af291))
* 新增獲取身份組的 API ([6e4cc3d](https://github.com/HSNM2/backend-nodejs/commit/6e4cc3dce00dede60ddb713c806e064cb4581cc0))
* 移除 lesson 沒使用到的變數 ([c939a6d](https://github.com/HSNM2/backend-nodejs/commit/c939a6d857438fb53aa8b63c67293262df00e25c))
* 設定 env ([67169ae](https://github.com/HSNM2/backend-nodejs/commit/67169ae2b8784a65debeee71d6f45a7ef101398b))
* 課程列表 limit 設定 ([6ae4f87](https://github.com/HSNM2/backend-nodejs/commit/6ae4f87eb4d686f88898ab624a2b5a5853e66f3d))
29 changes: 24 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
require('module-alias/register')
require('dotenv').config()
const express = require('express')
const app = express()
const cookieParser = require('cookie-parser')
const cors = require('cors')
const commonRouter = require('./routers/common')
const usersRouter = require('./routers/users')
const courseProviderRouter = require('./routers/courseProvider')
const coursesRouter = require('./routers/courses')
const courseRouter = require('./routers/course')
const cartRouter = require('./routers/cart')
require('./config/dbInit')

const corsOption = {
origin: '*',
origin: process.env['ORIGIN'],
credentials: true,
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
allowedHeaders: ['Content-Type', 'Authorization']
Expand All @@ -13,12 +22,22 @@ const corsOption = {
app.use(cookieParser())
app.use(cors(corsOption))
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.use('/static', express.static(__dirname + '/uploads'))

const API_PREFIX = '/api'
app.use(`${API_PREFIX}`, commonRouter)
app.use(`${API_PREFIX}/user`, usersRouter)
app.use(`${API_PREFIX}/courseProvider`, courseProviderRouter)
app.use(`${API_PREFIX}/courses`, coursesRouter)
app.use(`${API_PREFIX}/course`, courseRouter)
app.use(`${API_PREFIX}/cart`, cartRouter)

app.get('/', function(req, res) {
res.send('<h1>Hello World!</h1>')
app.get('/', function (req, res) {
res.send('<h1>Hello World!</h1>')
})

const port = process.env['PORT'] || 3002
app.listen(port, () => {
app.listen(port, () => {
console.log(`The application listening listening on port ${port}`)
})
})
23 changes: 23 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"development": {
"username": "paperhsiaooo",
"password": null,
"database": "nodedb_dev",
"host": "127.0.0.1",
"dialect": "postgres"
},
"test": {
"username": "postgres",
"password": null,
"database": "nodedb_test",
"host": "testsweettimedb.cwhwlslobxo9.ap-northeast-1.rds.amazonaws.com",
"dialect": "postgres"
},
"production": {
"username": "postgres",
"password": "123123123",
"database": "nodedb_production",
"host": "sweettimedb.cwhwlslobxo9.ap-northeast-1.rds.amazonaws.com",
"dialect": "postgres"
}
}
23 changes: 23 additions & 0 deletions config/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { Sequelize } = require('sequelize')
const env = process.env.NODE_ENV || 'development'
const config = require(__dirname + '/../config/config.json')[env]

let db = null
db = new Sequelize(config.database, config.username, config.password, {
host: config.host,
dialect: config.dialect
})

const testDBConnection = async () => {
try {
await db.authenticate()
console.log(`Connect has been established successfully.`)
} catch (error) {
console.error(`Unable to connect to the database: `, error)
}
}

module.exports = {
db,
testDBConnection
}
Loading

0 comments on commit f36f6bf

Please sign in to comment.