Toggle navigation
Toggle navigation
This project
Loading...
Sign in
정혜인
/
OSS
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Commits
Issue Boards
Authored by
진성욱
2021-10-04 18:49:28 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6b7cd19ab1042857204686eac05be73f4e92f7b8
6b7cd19a
1 parent
35288695
Change codes with EC6 Syntax
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
20 deletions
Experiments/express/assignments/assignment01/app.js
Experiments/express/assignments/assignment02/app.js
Experiments/express/assignments/assignment01/app.js
View file @
6b7cd19
var
express
=
require
(
'express'
);
var
app
=
express
();
var
bodyParser
=
require
(
'body-parser'
);
let
express
=
require
(
'express'
);
let
app
=
express
();
let
bodyParser
=
require
(
'body-parser'
);
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
false
}));
app
.
use
(
bodyParser
.
json
());
var
books
=
new
Array
();
let
books
=
new
Array
();
app
.
get
(
'/books/:bookId'
,
function
(
req
,
res
)
{
var
bookId
=
req
.
params
.
bookId
;
app
.
get
(
'/books/:bookId'
,
(
req
,
res
)
=>
{
let
bookId
=
req
.
params
.
bookId
;
console
.
log
(
books
[
bookId
]);
res
.
send
(
books
[
bookId
]);
});
...
...
@@ -23,21 +23,21 @@ app.get('/books/:bookId', function (req, res) {
"author" : "jin"
}
*/
app
.
post
(
'/books'
,
function
(
req
,
res
)
{
app
.
post
(
'/books'
,
(
req
,
res
)
=>
{
// Create book information
books
[
req
.
body
.
id
]
=
[
req
.
body
.
id
,
req
.
body
.
name
,
req
.
body
.
price
,
req
.
body
.
author
];
res
.
send
(
books
[
req
.
body
.
id
]);
})
app
.
put
(
'/books'
,
function
(
req
,
res
)
{
app
.
put
(
'/books'
,
(
req
,
res
)
=>
{
// Update book information
})
app
.
delete
(
'/books/:bookId'
,
function
(
req
,
res
)
{
app
.
delete
(
'/books/:bookId'
,
(
req
,
res
)
=>
{
// Delete book information
})
var
server
=
app
.
listen
(
80
);
let
server
=
app
.
listen
(
80
);
console
.
log
(
books
);
...
...
Experiments/express/assignments/assignment02/app.js
View file @
6b7cd19
var
express
=
require
(
'express'
);
var
app
=
express
();
var
bodyParser
=
require
(
'body-parser'
);
var
session
=
require
(
'express-session'
)
let
express
=
require
(
'express'
);
let
app
=
express
();
let
bodyParser
=
require
(
'body-parser'
);
let
session
=
require
(
'express-session'
)
app
.
use
(
session
({
secret
:
'keyboard cat'
,
cookie
:
{
maxAge
:
60000
}}))
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
false
}));
app
.
use
(
bodyParser
.
json
());
var
users
=
new
Array
();
let
users
=
new
Array
();
users
[
0
]
=
{
"userId"
:
0
,
"name"
:
"jin"
,
...
...
@@ -16,7 +16,7 @@ users[0] = {
"isAdmin"
:
true
}
app
.
put
(
'/login'
,
function
(
req
,
res
)
{
app
.
put
(
'/login'
,
(
req
,
res
)
=>
{
// users 배열에서 찾도록 처리 해야 함
// admin 여부를 확인하여 체크
// req.body.id : ID
...
...
@@ -25,7 +25,7 @@ app.put('/login', function (req, res) {
res
.
send
(
"Login"
);
});
app
.
put
(
'/logout'
,
function
(
req
,
res
)
{
app
.
put
(
'/logout'
,
(
req
,
res
)
=>
{
// Logout
// 세션 유효 여부를 체크하고 세션 Delete
req
.
session
.
userId
=
null
;
...
...
@@ -33,7 +33,7 @@ app.put('/logout', function (req, res) {
});
var
auth
=
function
(
req
,
res
,
next
)
{
let
auth
=
(
req
,
res
,
next
)
=>
{
// Session Check
// 어드민 여부 체크 필요
if
(
req
.
session
.
userId
!=
null
)
...
...
@@ -42,11 +42,11 @@ var auth = function (req, res, next) {
res
.
send
(
"Error"
);
};
app
.
get
(
'/user/:userId'
,
auth
,
function
(
req
,
res
)
{
app
.
get
(
'/user/:userId'
,
auth
,
(
req
,
res
)
=>
{
// get User Information
res
.
send
(
"OK"
);
});
// 사용자 추가 시에 admin 여부도 추가해야 함
var
server
=
app
.
listen
(
80
);
let
server
=
app
.
listen
(
80
);
...
...
Please
register
or
login
to post a comment