dckat

카페 리스트 API 호출

var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var createError = require("http-errors");
var express = require("express");
var path = require("path");
var cookieParser = require("cookie-parser");
var logger = require("morgan");
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var indexRouter = require("./routes/index");
var usersRouter = require("./routes/users");
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "ejs");
app.use(logger('dev'));
app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, "public")));
app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use("/", indexRouter);
app.use("/users", usersRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
app.use(function (req, res, next) {
next(createError(404));
});
// error handler
app.use(function(err, req, res, next) {
app.use(function (err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
res.locals.error = req.app.get("env") === "development" ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
res.render("error");
});
module.exports = app;
......
This diff is collapsed. Click to expand it.
......@@ -15,6 +15,7 @@
"http-errors": "~1.6.3",
"morgan": "~1.9.1",
"nodemon": "^2.0.7",
"request": "^2.88.2",
"session-file-store": "^1.5.0"
}
}
......
var express = require("express");
var router = express.Router();
var request = require("request");
var { OAuth2Client } = require("google-auth-library");
var querystring = require("querystring");
var CLIENT_ID =
"94679084723-s5f0686p2porp9mkakrp1p89a48n24nj.apps.googleusercontent.com";
var client = new OAuth2Client(CLIENT_ID);
......@@ -55,6 +59,37 @@ router.post("/login", (req, res) => {
console.log(req.body.gender);
return res.render("login", { user: req.session.user });
});
router.get("/cafe", (req, res) => {
let code = "CE7";
let encodedStr = querystring.escape(code);
let kakaoOptions = {
uri: `https://dapi.kakao.com/v2/local/search/category.json?category_group_code=${encodedStr}`,
method: "GET",
headers: {
Authorization: "KakaoAK 2f3999076db5d32db975ab9862a64480",
},
encoding: "utf-8",
};
request(kakaoOptions, callback);
function callback(error, res, body) {
console.log(body);
let kakaoPlaces = JSON.parse(body);
for (document of kakaoPlaces.documents) {
console.log(document.id);
console.log(document.place_name);
}
}
return;
});
router.get("/map", (req, res) => {
res.render("map");
});
module.exports = router;
function checkAuthenticated(req, res, next) {
......@@ -81,7 +116,3 @@ function checkAuthenticated(req, res, next) {
res.redirect("/index");
});
}
router.get("/map", (req, res) => {
res.render("map");
});
......
{"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"},"__lastAccess":1621216159014}
\ No newline at end of file
......@@ -30,20 +30,15 @@
var locPosition = new kakao.maps.LatLng(lat, lon);
displayMarker(locPosition);
displayCurrentPosition(locPosition);
});
} else {
var locPosition = new kakao.maps.LatLng(36.2477502, 127.078164);
displayMarker(locPosition);
displayCurrentPosition(locPosition);
}
function displayMarker(locPosition) {
var marker = new daum.maps.Marker({
map: map,
position: locPosition,
});
function displayCurrentPosition(locPosition) {
map.setCenter(locPosition);
}
</script>
......