Showing
2 changed files
with
20 additions
and
20 deletions
1 | -var express = require('express'); | 1 | +let express = require('express'); |
2 | -var app = express(); | 2 | +let app = express(); |
3 | -var bodyParser = require('body-parser'); | 3 | +let bodyParser = require('body-parser'); |
4 | 4 | ||
5 | app.use(bodyParser.urlencoded({ extended: false })); | 5 | app.use(bodyParser.urlencoded({ extended: false })); |
6 | app.use(bodyParser.json()); | 6 | app.use(bodyParser.json()); |
7 | 7 | ||
8 | 8 | ||
9 | -var books = new Array(); | 9 | +let books = new Array(); |
10 | 10 | ||
11 | -app.get('/books/:bookId', function (req, res) { | 11 | +app.get('/books/:bookId', (req, res) => { |
12 | - var bookId = req.params.bookId; | 12 | + let bookId = req.params.bookId; |
13 | console.log(books[bookId]); | 13 | console.log(books[bookId]); |
14 | res.send(books[bookId]); | 14 | res.send(books[bookId]); |
15 | }); | 15 | }); |
... | @@ -23,21 +23,21 @@ app.get('/books/:bookId', function (req, res) { | ... | @@ -23,21 +23,21 @@ app.get('/books/:bookId', function (req, res) { |
23 | "author" : "jin" | 23 | "author" : "jin" |
24 | } | 24 | } |
25 | */ | 25 | */ |
26 | -app.post('/books', function (req, res) { | 26 | +app.post('/books', (req, res) => { |
27 | // Create book information | 27 | // Create book information |
28 | books[req.body.id] = [req.body.id, req.body.name, req.body.price, req.body.author]; | 28 | books[req.body.id] = [req.body.id, req.body.name, req.body.price, req.body.author]; |
29 | res.send(books[req.body.id]); | 29 | res.send(books[req.body.id]); |
30 | }) | 30 | }) |
31 | 31 | ||
32 | -app.put('/books', function (req, res) { | 32 | +app.put('/books', (req, res) => { |
33 | // Update book information | 33 | // Update book information |
34 | 34 | ||
35 | }) | 35 | }) |
36 | 36 | ||
37 | 37 | ||
38 | -app.delete('/books/:bookId', function (req, res) { | 38 | +app.delete('/books/:bookId', (req, res) => { |
39 | // Delete book information | 39 | // Delete book information |
40 | 40 | ||
41 | }) | 41 | }) |
42 | -var server = app.listen(80); | 42 | +let server = app.listen(80); |
43 | console.log(books); | 43 | console.log(books); | ... | ... |
1 | -var express = require('express'); | 1 | +let express = require('express'); |
2 | -var app = express(); | 2 | +let app = express(); |
3 | -var bodyParser = require('body-parser'); | 3 | +let bodyParser = require('body-parser'); |
4 | -var session = require('express-session') | 4 | +let session = require('express-session') |
5 | 5 | ||
6 | app.use(session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }})) | 6 | app.use(session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }})) |
7 | app.use(bodyParser.urlencoded({ extended: false })); | 7 | app.use(bodyParser.urlencoded({ extended: false })); |
8 | app.use(bodyParser.json()); | 8 | app.use(bodyParser.json()); |
9 | 9 | ||
10 | 10 | ||
11 | -var users = new Array(); | 11 | +let users = new Array(); |
12 | users[0] = { | 12 | users[0] = { |
13 | "userId" : 0, | 13 | "userId" : 0, |
14 | "name" : "jin", | 14 | "name" : "jin", |
... | @@ -16,7 +16,7 @@ users[0] = { | ... | @@ -16,7 +16,7 @@ users[0] = { |
16 | "isAdmin" : true | 16 | "isAdmin" : true |
17 | } | 17 | } |
18 | 18 | ||
19 | -app.put('/login', function (req, res) { | 19 | +app.put('/login', (req, res) => { |
20 | // users 배열에서 찾도록 처리 해야 함 | 20 | // users 배열에서 찾도록 처리 해야 함 |
21 | // admin 여부를 확인하여 체크 | 21 | // admin 여부를 확인하여 체크 |
22 | // req.body.id : ID | 22 | // req.body.id : ID |
... | @@ -25,7 +25,7 @@ app.put('/login', function (req, res) { | ... | @@ -25,7 +25,7 @@ app.put('/login', function (req, res) { |
25 | res.send("Login"); | 25 | res.send("Login"); |
26 | }); | 26 | }); |
27 | 27 | ||
28 | -app.put('/logout', function (req, res) { | 28 | +app.put('/logout', (req, res) => { |
29 | // Logout | 29 | // Logout |
30 | // 세션 유효 여부를 체크하고 세션 Delete | 30 | // 세션 유효 여부를 체크하고 세션 Delete |
31 | req.session.userId = null; | 31 | req.session.userId = null; |
... | @@ -33,7 +33,7 @@ app.put('/logout', function (req, res) { | ... | @@ -33,7 +33,7 @@ app.put('/logout', function (req, res) { |
33 | 33 | ||
34 | }); | 34 | }); |
35 | 35 | ||
36 | -var auth = function (req, res, next) { | 36 | +let auth = (req, res, next) => { |
37 | // Session Check | 37 | // Session Check |
38 | // 어드민 여부 체크 필요 | 38 | // 어드민 여부 체크 필요 |
39 | if (req.session.userId != null) | 39 | if (req.session.userId != null) |
... | @@ -42,11 +42,11 @@ var auth = function (req, res, next) { | ... | @@ -42,11 +42,11 @@ var auth = function (req, res, next) { |
42 | res.send("Error"); | 42 | res.send("Error"); |
43 | 43 | ||
44 | }; | 44 | }; |
45 | -app.get('/user/:userId', auth,function (req, res) { | 45 | +app.get('/user/:userId', auth, (req, res) => { |
46 | // get User Information | 46 | // get User Information |
47 | res.send("OK"); | 47 | res.send("OK"); |
48 | }); | 48 | }); |
49 | 49 | ||
50 | // 사용자 추가 시에 admin 여부도 추가해야 함 | 50 | // 사용자 추가 시에 admin 여부도 추가해야 함 |
51 | 51 | ||
52 | -var server = app.listen(80); | 52 | +let server = app.listen(80); | ... | ... |
-
Please register or login to post a comment