dckat

카페 리스트 API 호출

1 -var createError = require('http-errors'); 1 +var createError = require("http-errors");
2 -var express = require('express'); 2 +var express = require("express");
3 -var path = require('path'); 3 +var path = require("path");
4 -var cookieParser = require('cookie-parser'); 4 +var cookieParser = require("cookie-parser");
5 -var logger = require('morgan'); 5 +var logger = require("morgan");
6 6
7 -var indexRouter = require('./routes/index'); 7 +var indexRouter = require("./routes/index");
8 -var usersRouter = require('./routes/users'); 8 +var usersRouter = require("./routes/users");
9 9
10 var app = express(); 10 var app = express();
11 11
12 // view engine setup 12 // view engine setup
13 -app.set('views', path.join(__dirname, 'views')); 13 +app.set("views", path.join(__dirname, "views"));
14 -app.set('view engine', 'ejs'); 14 +app.set("view engine", "ejs");
15 15
16 -app.use(logger('dev')); 16 +app.use(logger("dev"));
17 app.use(express.json()); 17 app.use(express.json());
18 app.use(express.urlencoded({ extended: false })); 18 app.use(express.urlencoded({ extended: false }));
19 app.use(cookieParser()); 19 app.use(cookieParser());
20 -app.use(express.static(path.join(__dirname, 'public'))); 20 +app.use(express.static(path.join(__dirname, "public")));
21 21
22 -app.use('/', indexRouter); 22 +app.use("/", indexRouter);
23 -app.use('/users', usersRouter); 23 +app.use("/users", usersRouter);
24 24
25 // catch 404 and forward to error handler 25 // catch 404 and forward to error handler
26 -app.use(function(req, res, next) { 26 +app.use(function (req, res, next) {
27 next(createError(404)); 27 next(createError(404));
28 }); 28 });
29 29
30 // error handler 30 // error handler
31 -app.use(function(err, req, res, next) { 31 +app.use(function (err, req, res, next) {
32 // set locals, only providing error in development 32 // set locals, only providing error in development
33 res.locals.message = err.message; 33 res.locals.message = err.message;
34 - res.locals.error = req.app.get('env') === 'development' ? err : {}; 34 + res.locals.error = req.app.get("env") === "development" ? err : {};
35 35
36 // render the error page 36 // render the error page
37 res.status(err.status || 500); 37 res.status(err.status || 500);
38 - res.render('error'); 38 + res.render("error");
39 }); 39 });
40 40
41 module.exports = app; 41 module.exports = app;
......
This diff is collapsed. Click to expand it.
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 "http-errors": "~1.6.3", 15 "http-errors": "~1.6.3",
16 "morgan": "~1.9.1", 16 "morgan": "~1.9.1",
17 "nodemon": "^2.0.7", 17 "nodemon": "^2.0.7",
18 + "request": "^2.88.2",
18 "session-file-store": "^1.5.0" 19 "session-file-store": "^1.5.0"
19 } 20 }
20 } 21 }
......
1 var express = require("express"); 1 var express = require("express");
2 var router = express.Router(); 2 var router = express.Router();
3 +var request = require("request");
4 +
3 var { OAuth2Client } = require("google-auth-library"); 5 var { OAuth2Client } = require("google-auth-library");
6 +var querystring = require("querystring");
7 +
4 var CLIENT_ID = 8 var CLIENT_ID =
5 "94679084723-s5f0686p2porp9mkakrp1p89a48n24nj.apps.googleusercontent.com"; 9 "94679084723-s5f0686p2porp9mkakrp1p89a48n24nj.apps.googleusercontent.com";
6 var client = new OAuth2Client(CLIENT_ID); 10 var client = new OAuth2Client(CLIENT_ID);
...@@ -55,6 +59,37 @@ router.post("/login", (req, res) => { ...@@ -55,6 +59,37 @@ router.post("/login", (req, res) => {
55 console.log(req.body.gender); 59 console.log(req.body.gender);
56 return res.render("login", { user: req.session.user }); 60 return res.render("login", { user: req.session.user });
57 }); 61 });
62 +
63 +router.get("/cafe", (req, res) => {
64 + let code = "CE7";
65 + let encodedStr = querystring.escape(code);
66 +
67 + let kakaoOptions = {
68 + uri: `https://dapi.kakao.com/v2/local/search/category.json?category_group_code=${encodedStr}`,
69 + method: "GET",
70 + headers: {
71 + Authorization: "KakaoAK 2f3999076db5d32db975ab9862a64480",
72 + },
73 + encoding: "utf-8",
74 + };
75 + request(kakaoOptions, callback);
76 +
77 + function callback(error, res, body) {
78 + console.log(body);
79 + let kakaoPlaces = JSON.parse(body);
80 +
81 + for (document of kakaoPlaces.documents) {
82 + console.log(document.id);
83 + console.log(document.place_name);
84 + }
85 + }
86 + return;
87 +});
88 +
89 +router.get("/map", (req, res) => {
90 + res.render("map");
91 +});
92 +
58 module.exports = router; 93 module.exports = router;
59 94
60 function checkAuthenticated(req, res, next) { 95 function checkAuthenticated(req, res, next) {
...@@ -81,7 +116,3 @@ function checkAuthenticated(req, res, next) { ...@@ -81,7 +116,3 @@ function checkAuthenticated(req, res, next) {
81 res.redirect("/index"); 116 res.redirect("/index");
82 }); 117 });
83 } 118 }
84 -
85 -router.get("/map", (req, res) => {
86 - res.render("map");
87 -});
......
1 +{"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"},"__lastAccess":1621216159014}
...\ No newline at end of file ...\ No newline at end of file
...@@ -30,20 +30,15 @@ ...@@ -30,20 +30,15 @@
30 30
31 var locPosition = new kakao.maps.LatLng(lat, lon); 31 var locPosition = new kakao.maps.LatLng(lat, lon);
32 32
33 - displayMarker(locPosition); 33 + displayCurrentPosition(locPosition);
34 }); 34 });
35 } else { 35 } else {
36 var locPosition = new kakao.maps.LatLng(36.2477502, 127.078164); 36 var locPosition = new kakao.maps.LatLng(36.2477502, 127.078164);
37 37
38 - displayMarker(locPosition); 38 + displayCurrentPosition(locPosition);
39 } 39 }
40 40
41 - function displayMarker(locPosition) { 41 + function displayCurrentPosition(locPosition) {
42 - var marker = new daum.maps.Marker({
43 - map: map,
44 - position: locPosition,
45 - });
46 -
47 map.setCenter(locPosition); 42 map.setCenter(locPosition);
48 } 43 }
49 </script> 44 </script>
......