ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ


์•„์ง ์™„์„ฑ๋ณธ์€ ์•„๋‹ˆ์ง€๋งŒ ๋””์ž์ธ์€ ์ข€ ๋’ค๋กœํ•˜๊ณ  ๊ธฐ๋ณธ์ ์ธ ๊ฒŒ์‹œํŒ ๊ธฐ๋Šฅ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๊ฒŒ์‹œํŒ์„ ๋งŒ๋“ค์–ด๋ณด๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค.


์‚ฌ์šฉ์–ธ์–ด ๋ฐ ๋„๊ตฌ๋Š” html(pugํ…œํ”Œ๋ฆฟ ์‚ฌ์šฉ), css, jquery, javascript, node.js, mysql (sequelize ์‚ฌ์šฉ) ์ •๋„ ์ž…๋‹ˆ๋‹ค. 


ํ˜„์žฌ ์ง„ํ–‰์‚ฌํ•ญ ๋ฐ ๊ณ„ํš์€

1. ๊ฒŒ์‹œํŒ ๊ธ€ ๋กœ๋“œ (์™„๋ฃŒ)

2. ํŽ˜์ด์ง€ ๋ถ„ํ•  (์•„์ง ์ž‘์—… ์‹œ์ž‘ ์•ˆ ํ•จ)

3. ์กฐํšŒ ์ˆ˜ (์™„๋ฃŒ)

4. ๊ธ€ ์“ฐ๊ธฐ (ํผ ์ˆ˜์ • ์ž‘์—… ํ•„์š”)

5. ๋Œ“๊ธ€๊ธฐ๋Šฅ(์•„์ง ์ž‘์—… ์‹œ์ž‘ ์•ˆ ํ•จ)

5. ๊ฒŒ์‹œ๊ธ€ ๋ณด๊ธฐ (ํผ ์ˆ˜์ • ์ž‘์—… ํ•„์š”)

6. ๋ณธ์ธ ๊ฒŒ์‹œ๊ธ€ ์ˆ˜์ • (์•„์ง ์ž‘์—… ์‹œ์ž‘ ์•ˆ ํ•จ)

7. ๊ฒŒ์‹œ๊ธ€ ๊ฒ€์ƒ‰ (์ž‘์„ฑ์ž ์ด๋ฆ„๋งŒ ์ž‘์—… ์™„๋ฃŒ. ์ œ๋ชฉ+๋‚ด์šฉ ์—…๋ฐ์ดํŠธ ์˜ˆ์ •)


์ผ๋‹จ์€ ์ด ์ •๋„ ์ž…๋‹ˆ๋‹ค. ์ง€๊ธˆ๊นŒ์ง€ ์ž‘์—…ํ•œ ํŽ˜์ด์ง€์˜ ๊ฐ„๋‹จํ•œ ๋™์ž‘ ์˜์ƒ์„ gif ํŒŒ์ผ๋กœ ๋งŒ๋“ค์–ด ๋ณด์•˜์Šต๋‹ˆ๋‹ค.

0





๊ธฐ์กด์— ์ž‘์—…ํ•˜๋˜ ํŽ˜์ด์ง€์— ํ•˜๋˜ ํ„ฐ๋ผ ๋กœ๊ทธ์ธ์ด๋‚˜ ๊ธฐํƒ€ ํ™”๋ฉด๋“ค์ด ๊ฐ™์ด ๋“ค์–ด๊ฐ€ ์žˆ๊ธด ํ•ฉ๋‹ˆ๋‹ค. ๊ฒŒ์‹œํŒ ํŽ˜์ด์ง€์— ์˜ํ–ฅ์„ ์ฃผ๋Š” ํŒŒ์ผ์„ ์ค‘์ ์ ์œผ๋กœ ํฌ์ŠคํŒ… ํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.


์ผ๋‹จ ๊ธฐ๋ณธ ๋””๋ ‰ํ† ๋ฆฌ ๊ตฌ์กฐ์ž…๋‹ˆ๋‹ค.


๋‹ค๋ฅธ ์žก๋‹คํ•œ ํŒŒ์ผ๋“ค์ด ๋งŽ์•„์„œ ํ‘œ์‹œํ•œ ํŒŒ์ผ๋“ค์ด ์ด ์ฃผ์ œ์— ๊ด€๋ จ์ด ์žˆ๋Š” ํŒŒ์ผ๋“ค ์ž…๋‹ˆ๋‹ค.


1. app_mvc.js - app.js ํŒŒ์ผ์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. 

2. routes - ๊ฐ์ข… ๋ผ์šฐํ„ฐ๋“ค์ด ์žˆ๋Š” ๋””๋ ‰ํ† ๋ฆฌ์ž…๋‹ˆ๋‹ค.

3. views - ์•ž๋‹จ์ด ์žˆ๋Š” ๋””๋ ‰ํ† ๋ฆฌ์ž…๋‹ˆ๋‹ค. html ํŒŒ์ผ๋“ค ์ €๋Š” pug ํ…œํ”Œ๋ฆฟ์„ ์‚ฌ์šฉํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— pug ํŒŒ์ผ๋“ค์ด ๋“ค์–ด์žˆ์Šต๋‹ˆ๋‹ค.

4. bin - npm start๋ฅผ ํ–ˆ์„ ๋•Œ ์‹คํ–‰๋˜๋Š” www ํŒŒ์ผ์ด ์žˆ๋Š”๋ฐ ๊ฐœ์ธ ํ™˜๊ฒฝ์— ๋งž๊ฒŒ๋” ํŒŒ์ผ๋ช…์ด๋‚˜ ํฌํŠธ๋ฒˆํ˜ธ๋ฅผ ๋ณ€๊ฒฝํ•˜๊ฑฐ๋‚˜ ํ˜น์€ app.js ํŒŒ์ผ์— listen์„ ์ถ”๊ฐ€ํ•˜์—ฌ node ๋ช…๋ น์–ด๋กœ app.js ํŒŒ์ผ์„ ์‹คํ–‰์‹œ์ผœ๋„ ๋ฉ๋‹ˆ๋‹ค.

5. models - ๊ฐ ํ…Œ์ด๋ธ”๋“ค์˜ ์ •์˜๊ฐ€ ์žˆ๋Š” ๋””๋ ‰ํ† ๋ฆฌ ์ž…๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ๋Š” board์™€ user ํŒŒ์ผ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

6. config - sequelize ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ๊ธฐ๋ณธ ์„ค์ •์ด ์žˆ๋Š” ํŒŒ์ผ์ด ๋“ค์–ด์žˆ์Šต๋‹ˆ๋‹ค.

7. function - ์‚ฌ์šฉ์ž ์ •์˜ ํ•จ์ˆ˜๋“ค์„ ๋ชจ์•„๋†“์€ ๋””๋ ‰ํ† ๋ฆฌ ์ž…๋‹ˆ๋‹ค.


๊ทธ ์™ธ์— ์ƒ๋žต๋œ ๊ฒƒ์€ ๊พธ๋ฏธ๋Š” ์šฉ๋„ ์ด๊ฑฐ๋‚˜ ํ˜น์€ ์‚ฌ์šฉ์ž๋งˆ๋‹ค ๋‹ค๋ฅธ ํŒŒ์ผ๋“ค ์ž…๋‹ˆ๋‹ค.


[ app_mvc.js ]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session')
var passport = require('passport')
var sequelize = require('sequelize')
var bodyParser = require('body-parser');
var models = require('./models')
var app = express();
 
//app.get
var indexRouter = require('./routes/index');
var headerRouter = require('./routes/header');
var aboutRouter = require('./routes/about');
var practiceRouter = require('./routes/practice');
var mypageRouter = require('./routes/mypage');
var loginRouter = require('./routes/login');
var enrollRouter = require('./routes/enroll');
var commuityRouter = require('./routes/commuity')
var commuityIdRouter = require('./routes/commuity_id')
var logoutRouter = require('./routes/logout');
var writeRouter = require('./routes/write');
var facebookRouter = require('./routes/facebook');
var facebookCallbackRouter = require('./routes/facebook_callback');
var facebookSuccessRouter = require('./routes/login_success')
//app.post
var loginReceiveRouter = require('./routes/login_receive');
var writeReceiveRouter = require('./routes/write_receive');
var enrollReceiveRouter = require('./routes/enroll_receive');
//sequelize
models.sequelize.sync()
    .then(function() {
    console.log('โœ“ DB connection success.');
      console.log('  Press CTRL-C to stop\n');
  })
  .catch(function(err) {
    console.error(err);
    console.log('โœ— DB connection error. Please make sure DB is running.');
    process.exit();
  });
 
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine''pug');
 
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(cookieParser())
app.use(session({
    secret:'123123123',
    resave:false,
    saveUninitialize:true
}));
app.use(express.static(__dirname));
app.use(passport.initialize());
app.use(passport.session());
 
//get
app.use('/', indexRouter);
app.use('/header',headerRouter);
app.use('/about',aboutRouter);
app.use('/practice',practiceRouter);
app.use('/mypage',mypageRouter);
app.use('/enroll',enrollRouter);
app.use('/login',loginRouter);
app.use('/commuity',commuityRouter);
app.use('/commuity',commuityIdRouter);
app.use('/logout',logoutRouter);
app.use('/write',writeRouter);
app.use('/auth/facebook',facebookRouter);
app.use('/auth/facebook/callback',facebookCallbackRouter);
app.use('/login_success',facebookSuccessRouter);
 
//post
app.use('/login_receive',loginReceiveRouter);
app.use('/write_receive',writeReceiveRouter);
app.use('/enroll_receive',enrollReceiveRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
  next(createError(404));
});
 
// error handler
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env'=== 'development' ? err : {};
 
  // render the error page
  res.status(err.status || 500);
  res.render('error');
});
module.exports = app;
cs


[ commuity.js ]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var express = require('express')
var router = express.Router()
var app = express();
var path = require('path')
var board = require('../function/board')
app.set('views',path.join(__dirname,'views'));
app.set('view engine','pug')
 
router.get('/',function(req,res){
    board.boardLoadFunction(function(result){
        var jsonStr = JSON.stringify(result);
        if(result.length==0)
            res.render('commuity',{data:0})
        else
            res.render('commuity',{data:jsonStr})
    })
})
 
module.exports = router;
cs


[ commuity_id.js ]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var express = require('express')
var router = express.Router()
var app = express();
var path = require('path')
var board = require('../function/board')
var models = require('../models')
app.set('views',path.join(__dirname,'views'));
app.set('view engine','pug')
 
router.get('/:id',function(req,res){
    var id = req.params.id;
    models.Board.findAll({
        where: {'id':id}
    }).then(function(result){
        models.Board.update({count:++result[0].dataValues.count},
            {where: {'id':id} })
        var jsonObj = JSON.stringify(result)
        res.render('commuity_detail',{data:jsonObj})
    })
})
 
module.exports = router;
cs


๊ธฐ๋ณธ์ ์œผ๋กœ app_mvc.js ํŒŒ์ผ์ด ์‹คํ–‰๋˜์–ด์„œ routes์— ์žˆ๋Š” commuity์— ๊ด€๋ จ๋œ pug ํŒŒ์ผ์„ ๋ Œ๋”๋งํ•ด์„œ ์‹คํ–‰๋˜๋Š” ๊ตฌ์กฐ์ž…๋‹ˆ๋‹ค.


๋ฌผ๋ก  routes ๋””๋ ‰ํ† ๋ฆฌ ์•ˆ ํŒŒ์ผ๋“ค์— ์ž‘์„ฑ๋˜์–ด์žˆ๋Š” ๊ฐ์ข… ํ•จ์ˆ˜๋“ค์€ function์— ์ž‘์„ฑํ•ด๋†“์€ ํŒŒ์ผ๋“ค์ด๊ณ  ๋ชจ๋“ˆ์€ npm์„ ์ด์šฉํ•ด์„œ ์„ค์น˜๊ฐ€


ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  DB๋ฅผ ๊ณ„์† ๋Œ๊ณ  ๋‹ค๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์— Sequelize ์„ค์ •์ด ์ œ๋Œ€๋กœ ๋˜์ง€ ์•Š์œผ๋ฉด ์˜ค๋ฅ˜๊ฐ€ ๋‚  ์ˆ˜ ๋ฐ–์— ์—†์Šต๋‹ˆ๋‹ค.



์ž‘์—… ์ดˆ๊ธฐ๋ถ€ํ„ฐ ํฌ์ŠคํŒ…์„ ํ•˜์ง€ ๋ชปํ•˜๊ฒŒ ๋˜์–ด ์ผ๋‹จ ์ฒซ ๊ฒŒ์‹œ๋ฌผ์€ ๋Œ€์ฒด์ ์œผ๋กœ ์ด๋ ‡๋‹ค๋Š” ๋ชจ์Šต์„ ๋ณด์—ฌ ๋“œ๋ฆฝ๋‹ˆ๋‹ค. ์ด์ „์— ํ–ˆ๋˜ ์ž‘์—…๋“ค๋„ ๋ณด์ถฉ์„ค๋ช…์„ ๊ณ๋“ค์—ฌ ํฌ์ŠคํŒ… ํ•˜๊ณ , ์•ž์œผ๋กœ ์—…๋ฐ์ดํŠธ๋˜๋Š” ๊ฒŒ์‹œ๋ฌผ๋„ ๋™์‹œ์— ์ง„ํ–‰ํ•  ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.


ํ˜„์žฌ ์ง„ํ–‰์ค‘์ธ ์ž‘์—…์€ https://github.com/JooHyeongLee/webserver_nodejs

์—ฌ๊ธฐ์— ์ง€์†์ ์œผ๋กœ ์—…๋ฐ์ดํŠธ ํ•  ์˜ˆ์ •์ด๋ฉฐ ์˜ค๋ฅ˜๊ฐ€ ์ƒ๊ธฐ๋Š” ๋ถ€๋ถ„์ด ์žˆ์œผ๋ฉด ๋Œ“๊ธ€ ๋‚จ๊ฒจ์ฃผ์„ธ์š”~ 


์ˆœ์ˆ˜ํ•œ ๊ฒŒ์‹œํŒ ํŽ˜์ด์ง€๋ฅผ ๊ตฌํ˜„ํ•œ ํ”„๋กœ์ ํŠธ ํŒŒ์ผ์ด ์•„๋‹ˆ๋‹ค๋ณด๋‹ˆ ์—ฌ๊ธฐ์ €๊ธฐ ์ถฉ๋Œ๋‚˜๋Š” ๋ถ€๋ถ„์ด ์ƒ๊ธธ ์ˆ˜ ๋ฐ–์— ์—†์„ ๋“ฏ ํ•˜๋„ค์š” ใ… 


๋Œ“๊ธ€
๊ณต์ง€์‚ฌํ•ญ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€
Total
Today
Yesterday
๋งํฌ
ยซ   2025/01   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
๊ธ€ ๋ณด๊ด€ํ•จ