최동원

api fix

...@@ -50,10 +50,10 @@ app.use(express.static('views')); ...@@ -50,10 +50,10 @@ app.use(express.static('views'));
50 app.use(passport.initialize()); 50 app.use(passport.initialize());
51 app.use(passport.session()); 51 app.use(passport.session());
52 52
53 -app.use('/', indexRouter); 53 +app.use('/api/', indexRouter);
54 -app.use('/user', userRouter); 54 +app.use('/api/user', userRouter);
55 -app.use('/login', loginRouter); 55 +app.use('/api/login', loginRouter);
56 -app.use('/RegistUser', registerRouter); 56 +app.use('/api/RegistUser', registerRouter);
57 //app.use('/users', usersRouter); 57 //app.use('/users', usersRouter);
58 58
59 // catch 404 and forward to error handler 59 // catch 404 and forward to error handler
......
...@@ -20,7 +20,7 @@ router.post('/', function(req, res, next) { ...@@ -20,7 +20,7 @@ router.post('/', function(req, res, next) {
20 if(bytes===user_pw) { 20 if(bytes===user_pw) {
21 console.log("user login successfully"); 21 console.log("user login successfully");
22 req.session.user_id=result[0].user_id; 22 req.session.user_id=result[0].user_id;
23 - res.redirect('/main'); 23 + res.status(200).send({ user_id: result[0].user_id });
24 }else{ 24 }else{
25 console.log("wrong password!"); 25 console.log("wrong password!");
26 } 26 }
......
...@@ -21,7 +21,7 @@ router.post('/', function(req, res, next) { ...@@ -21,7 +21,7 @@ router.post('/', function(req, res, next) {
21 var user_phone=req.body.user_phone; 21 var user_phone=req.body.user_phone;
22 22
23 var sqlquery = "SELECT * FROM users WHERE user_id = ?"; 23 var sqlquery = "SELECT * FROM users WHERE user_id = ?";
24 - connection.query(sqlquery, [user_id], function (err, result) { 24 + connection.query(sqlquery, [user_id], function (err, rows) {
25 if (rows.length == 0) { 25 if (rows.length == 0) {
26 user_pw=cryptoM.encrypt(user_pw); 26 user_pw=cryptoM.encrypt(user_pw);
27 console.log(user_pw); 27 console.log(user_pw);
...@@ -32,13 +32,12 @@ router.post('/', function(req, res, next) { ...@@ -32,13 +32,12 @@ router.post('/', function(req, res, next) {
32 console.log("inserting user failed"); 32 console.log("inserting user failed");
33 throw err; 33 throw err;
34 } else { 34 } else {
35 - res.redirect('/login'); 35 + res.status(200).send('saved');
36 36
37 } 37 }
38 }); 38 });
39 } else { 39 } else {
40 - res.redirect("/login"); 40 + res.status(404).send(err);
41 - throw err;
42 } 41 }
43 }); 42 });
44 }); 43 });
......