π οΈ Tech Stacks
βοΈ Development Enviroment
1. git clone
git clone https://github.com/BenchPress200/community-server-express.git
2. vscodeλ‘ νλ‘μ νΈ open
- νλμ μ°½μ community-server-express/frontend-server
- λ€λ₯Έ νλμ μ°½μ community-server-express/backtend-server
3. package-lock.json μμ±
- λ κ°μ vscode μ°½μμ κ°κ° ν°λ―Έλμ μ΄μ΄μ npm install λͺ λ ΉμΌλ‘ package-lock.json μμ±
npm install
4. globals.js μμ νλ‘ νΈμλ μλ²μ λ°±μλ μλ²μ IP μ£Όμμ Port λ²νΈ μΈν
π community-server-express/frontend-server/public/javascript/globals.js
π community-server-express/backend-server/globals.js
β λ κ°μ globals.jsλ₯Ό λκ°μ΄ μμ±ν΄μΌ ν¨
5. μλ² μ€ν
- front, back κ°κ° ν°λ―Έλμμ npm startλ₯Ό ν΅ν΄ μ€ν
npm start
6. Welcome Page
- globals.jsμμ FRONTEND_IP_PORTμ ν λΉνλ μ£Όμλ₯Ό λΈλΌμ°μ μμ μ£Όμμ°½μ μ λ ₯
export const FRONTEND_PORT = 8080;
export const FRONTEND_IP_PORT = `http://localhost:${FRONTEND_PORT}`;
β¬οΈ μ μ²λΌ μμ±νλ€λ©΄ http://localhost:8080 μ¬μ©
π community-server-express
|
| - π frontend-server
| |
| | - π public # css, js, globals.js
| | - π routes # μ μ , κ²μλ¬Ό λΌμ°ν° λͺ¨λ
| | - π view # html
| | - app.js # νλ‘ νΈμλ μλ² λ©μΈ
|
| - π backend-server
|
| - π routes # μ μ , κ²μλ¬Ό λΌμ°ν° λͺ¨λ
| - π controllers # λΌμ°ν°μ λͺ¨λΈμ μ€κ³, μ μ -κ²μλ¬Ό 컨νΈλ‘€λ¬
| - π models # μ μ -κ²μλ¬Ό λͺ¨λΈ, json λλ―Έ λ°μ΄ν°
| - globals.js # IP μ£Όμ, port λ²νΈ
| - app.js # λ°±μλ μλ² λ©μΈ
- DBμ¬μ© β
- json νμΌλ‘ λ°μ΄ν° κ΄λ¦¬
- μΈμ μΌλ‘ μΈμ¦, μΈκ° ꡬν
-
μ΄κΈ°λ°μ΄ν° μΈν
- μ΅μ΄ μ€ν μ, community-server-express/backend-server/models/repository/μ μμ΄μΌν μ μ , κ²μκΈ, λκΈ jsonμμ
function initData(req, res, next) {
if (!fs.existsSync(path.join(__dirname, usersDataPath))) {
const adminData = [
{
id: 0,
email: '*******',
password: '*****',
nickname: 'admin',
profileImage: "data:image/jpeg;base64,..."
}
];
fs.writeFileSync(path.join(__dirname, usersDataPath), JSON.stringify(adminData), 'utf8');
}
if (!fs.existsSync(path.join(__dirname, postsDataPath))) {
const adminPostData = [
{
id: 0,
writer: 0,
title: 'νμν©λλ€!',
time: '2024-05-01 11:00:00',
image: '',
content: 'λ°κ°μ΅λλ€. νμν©λλ€.',
likes: 0,
hits: 0,
comments: 0
}
];
fs.writeFileSync(path.join(__dirname, postsDataPath), JSON.stringify(adminPostData), 'utf8');
}
if (!fs.existsSync(path.join(__dirname, commentsDataPath))) {
const adminPostData = [
{
id: 0,
postId: 0,
writer: 0,
time: '2024-05-01 11:00:00',
text: 'λ°κ°μ΅λλ€.'
}
];
fs.writeFileSync(path.join(__dirname, commentsDataPath), JSON.stringify(adminPostData), 'utf8');
}
next();
}
λ€μκ³Ό κ°μ΄, ν΄λΉ μ΄κΈ°ν ν¨μλ₯Ό μ μ λΌμ°ν°μ λ―Έλ€μ¨μ΄λ‘ λ±λ‘ users.json, posts.json, comments.jsonμ΄ μλ€λ©΄ μ΄κΈ°λ°μ΄ν°λ‘ μμ±ν΄λ²λ¦Ό
-
ν΄λ¦ μμλ€μ λν λ§μ°μ€ ν¬μΈν° λ³κ²½ -
λ²νΌλ€ λͺ¨λ νΈλ² μΆκ° -
λΉλ°λ²νΈ μ λ ₯κ³Ό λΉλ°λ²νΈ νμΈ μ λ ₯ μ€ νλλ§ μ λ ₯νμ λ μ μ ν ν¬νΌν μ€νΈλ‘ μμ -
form μ μΆμ ν΅ν μ΄λ―Έμ§ μ μ₯μμ νμΌ κ²½λ‘κ° μλ data-urlλ‘ μ μ₯ -
λ‘κ·ΈμΈ λ²νΌμ ν΅ν΄ λ‘κ·ΈμΈ μλ£ ν, ν΄λΉ λ²νΌμ΄ κ³μ ν΄λ¦λλ μ΄μ -
ν¬νΌν μ€νΈλ‘ μΈν΄ νΌ μμ λ°λ¦¬λ μ΄μ -
κ°μ’ μ ν¨μ± κ²μ¬λ₯Ό μμν¬μ»€μ±μ΄ μλ μ¦μ μ λ ₯μ νλ¨μΌλ‘ μ ν¨μ± κ²μ¬ μ§ν -
νμκ°μ νμ΄μ§ ν¬νΌν μ€νΈ μ€ν μ΄μ