진성욱

Change codes with EC6 Syntax

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);
......
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);
......