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
Dexter Jin
2020-02-02 15:37:23 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
14327d132bd4f6a70c9e517a8809c5679b1cb185
14327d13
1 parent
7b066cf4
Update Experiment09
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
120 additions
and
0 deletions
Experiments/experiments08/assignments/assignment01/app.js
Experiments/experiments08/assignments/assignment01/package.json
Experiments/experiments08/assignments/assignment02/app.js
Experiments/experiments08/assignments/assignment02/package.json
Experiments/experiments08/assignments/assignment01/app.js
0 → 100644
View file @
14327d1
var
express
=
require
(
'express'
);
var
app
=
express
();
var
bodyParser
=
require
(
'body-parser'
);
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
false
}));
app
.
use
(
bodyParser
.
json
());
var
books
=
new
Array
();
app
.
get
(
'/books/:bookId'
,
function
(
req
,
res
)
{
var
bookId
=
req
.
params
.
bookId
;
console
.
log
(
books
[
bookId
]);
res
.
send
(
books
[
bookId
]);
});
/*
* json representation of book object
{
"id" : 2,
"name" : "book2",
"price" : 2000,
"author" : "jin"
}
*/
app
.
post
(
'/books'
,
function
(
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
)
{
// Update book information
})
app
.
delete
(
'/books/:bookId'
,
function
(
req
,
res
)
{
// Delete book information
})
var
server
=
app
.
listen
(
80
);
console
.
log
(
books
);
Experiments/experiments08/assignments/assignment01/package.json
0 → 100644
View file @
14327d1
{
"name"
:
"assignment01"
,
"version"
:
"1.0.0"
,
"description"
:
""
,
"main"
:
"index.js"
,
"scripts"
:
{
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
},
"author"
:
""
,
"license"
:
"ISC"
,
"dependencies"
:
{
"body-parser"
:
"^1.17.1"
,
"express"
:
"^4.15.2"
}
}
Experiments/experiments08/assignments/assignment02/app.js
0 → 100644
View file @
14327d1
var
express
=
require
(
'express'
);
var
app
=
express
();
var
bodyParser
=
require
(
'body-parser'
);
var
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
();
app
.
get
(
'/login'
,
function
(
req
,
res
)
{
// users 배열에서 찾도록 처리 해야 함
// admin 여부를 확인하여 체크
// req.body.id : ID
// req.body.name : 패스워드
res
.
send
(
"Login"
);
});
app
.
get
(
'/logout'
,
function
(
req
,
res
)
{
// Logout
// 세션 유효 여부를 체크하고 세션 Delete
req
.
session
.
userId
=
null
;
res
.
send
(
"LogOut"
);
});
var
auth
=
function
(
req
,
res
,
next
)
{
// Session Check
// 어드민 여부 체크 필요
if
(
req
.
session
.
userId
!=
null
)
next
();
else
res
.
send
(
"Error"
);
};
app
.
get
(
'/user/:userId'
,
auth
,
function
(
req
,
res
)
{
// get User Information
res
.
send
(
"OK"
);
});
// 사용자 추가 시에 admin 여부도 추가해야 함
var
server
=
app
.
listen
(
80
);
Experiments/experiments08/assignments/assignment02/package.json
0 → 100644
View file @
14327d1
{
"name"
:
"assignment02"
,
"version"
:
"1.0.0"
,
"description"
:
""
,
"main"
:
"index.js"
,
"scripts"
:
{
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
},
"author"
:
""
,
"license"
:
"ISC"
,
"dependencies"
:
{
"body-parser"
:
"^1.17.1"
,
"express"
:
"^4.15.2"
,
"express-session"
:
"^1.15.2"
}
}
Please
register
or
login
to post a comment