Showing
3 changed files
with
81 additions
and
65 deletions
| 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 | -var app = express(); | 6 | +// var app = express(); |
| 7 | -const mongodb = require('mongodb'); | 7 | +// const mongodb = require('mongodb'); |
| 8 | -const MongoClient = mongodb.MongoClient; | 8 | +// const MongoClient = mongodb.MongoClient; |
| 9 | 9 | ||
| 10 | -const url = 'mongodb+srv://hellowhales:qogudtjr`12@cluster0.7gz7l.mongodb.net/myFirstDatabase?retryWrites=true&w=majority'; | 10 | +// const url = 'mongodb+srv://hellowhales:qogudtjr`12@cluster0.7gz7l.mongodb.net/myFirstDatabase?retryWrites=true&w=majority'; |
| 11 | 11 | ||
| 12 | -let db; | 12 | +// let db; |
| 13 | 13 | ||
| 14 | -app.use(express.urlencoded({ extended: true })) | 14 | +// app.use(express.urlencoded({ extended: true })) |
| 15 | 15 | ||
| 16 | -// 터미널창 연결방법 mongo 'mongodb+srv://hellowhales:qogudtjr`12@cluster0.7gz7l.mongodb.net/myFirstDatabase?retryWrites=true&w=majority'; | 16 | +// // 터미널창 연결방법 mongo 'mongodb+srv://hellowhales:qogudtjr`12@cluster0.7gz7l.mongodb.net/myFirstDatabase?retryWrites=true&w=majority'; |
| 17 | -// db.festivals.find({"title":"가무악극으로 만나는 토요 상설공연"}) 검색방법 | 17 | +// // db.festivals.find({"title":"가무악극으로 만나는 토요 상설공연"}) 검색방법 |
| 18 | 18 | ||
| 19 | -//https://www.mongodb.com/try/download/database-tools?tck=docs_databasetools 여기서 mongoexport 실행을 위한 tool 다운받아서 Program files/mongodb/bin 폴더 안에 넣어줘야 함 | 19 | +// //https://www.mongodb.com/try/download/database-tools?tck=docs_databasetools 여기서 mongoexport 실행을 위한 tool 다운받아서 Program files/mongodb/bin 폴더 안에 넣어줘야 함 |
| 20 | 20 | ||
| 21 | -MongoClient.connect(url, (error, client) => { // 서버열때 url 사용 mongoDB와 연결시키기 | 21 | +// MongoClient.connect(url, (error, client) => { // 서버열때 url 사용 mongoDB와 연결시키기 |
| 22 | - if (error) return console.log(error); | 22 | +// if (error) return console.log(error); |
| 23 | - db = client.db('myFirstDatabase'); // 클러스터의 데이터베이스를 db변수에 저장 | 23 | +// db = client.db('myFirstDatabase'); // 클러스터의 데이터베이스를 db변수에 저장 |
| 24 | - app.listen(3001, () => { | 24 | +// app.listen(3001, () => { |
| 25 | - console.log('3001 port on'); | 25 | +// console.log('3001 port on'); |
| 26 | - }); | 26 | +// }); |
| 27 | -}); | 27 | +// }); |
| 28 | 28 | ||
| 29 | -app.get('/festivalList', (req, res) => { // localhost:3000/festivalList 입력하면 list.ejs에 저장한 형식대로 정보 불러와짐 | 29 | +// app.get('/festivalList', (req, res) => { // localhost:3000/festivalList 입력하면 list.ejs에 저장한 형식대로 정보 불러와짐 |
| 30 | - //디비에 저장된 festivals 라는 collection안의 데이터(제목 또는 내용 등)를 꺼내기 | 30 | +// //디비에 저장된 festivals 라는 collection안의 데이터(제목 또는 내용 등)를 꺼내기 |
| 31 | - db.collection('festivals').find().toArray((err, rslt) => { //DB에서 데이터를 찾음 festivals라는 collection안의 데이터를 꺼내게 됨 | 31 | +// db.collection('festivals').find().toArray((err, rslt) => { //DB에서 데이터를 찾음 festivals라는 collection안의 데이터를 꺼내게 됨 |
| 32 | - if (err) throw err; | 32 | +// if (err) throw err; |
| 33 | - console.log(rslt); | 33 | +// console.log(rslt); |
| 34 | - res.render('list.ejs', { posts: rslt }); // 찾은 데이터를 ejs 파일에 넣음 | 34 | +// res.render('list.ejs', { posts: rslt }); // 찾은 데이터를 ejs 파일에 넣음 |
| 35 | - }); | 35 | +// }); |
| 36 | -}); | 36 | +// }); |
| 37 | 37 | ||
| 38 | 38 | ||
| 39 | 39 | ||
| 40 | -// 서버 연결하고 mongoexport 설치 후 mongoexport -d myFirstDatabase -c festivals -o festivalList.json /pretty 'mongodb+srv://hellowhales:qogudtjr`12@cluster0.7gz7l.mongodb.net/myFirstDatabase?retryWrites=true&w=majority' 명령 | 40 | +// // 서버 연결하고 mongoexport 설치 후 mongoexport -d myFirstDatabase -c festivals -o festivalList.json /pretty 'mongodb+srv://hellowhales:qogudtjr`12@cluster0.7gz7l.mongodb.net/myFirstDatabase?retryWrites=true&w=majority' 명령 |
| 41 | -// 이용해서 myFirstDatabase라는 Db 안에서 festivals라는 collection 안의 데이터를 festivalList.json 파일로 export 해옴. | 41 | +// // 이용해서 myFirstDatabase라는 Db 안에서 festivals라는 collection 안의 데이터를 festivalList.json 파일로 export 해옴. |
| 42 | 42 | ||
| 43 | 43 | ||
| 44 | -var indexRouter = require('./routes/index'); | 44 | +// var indexRouter = require('./routes/index'); |
| 45 | -var usersRouter = require('./routes/users'); | 45 | +// var usersRouter = require('./routes/users'); |
| 46 | -const { mongo } = require('mongoose'); | 46 | +// const { mongo } = require('mongoose'); |
| 47 | 47 | ||
| 48 | 48 | ||
| 49 | 49 | ||
| 50 | -// view engine setup | 50 | +// // view engine setup |
| 51 | 51 | ||
| 52 | -app.set('views', path.join(__dirname, 'views')); | 52 | +// app.set('views', path.join(__dirname, 'views')); |
| 53 | -app.set('view engine', 'ejs'); // express에서 view엔진을 ejs로 설정하는과정 | 53 | +// app.set('view engine', 'ejs'); // express에서 view엔진을 ejs로 설정하는과정 |
| 54 | 54 | ||
| 55 | 55 | ||
| 56 | 56 | ||
| 57 | -app.use(logger('dev')); | 57 | +// app.use(logger('dev')); |
| 58 | -app.use(express.json()); | 58 | +// app.use(express.json()); |
| 59 | -app.use(express.urlencoded({ extended: false })); | 59 | +// app.use(express.urlencoded({ extended: false })); |
| 60 | -app.use(cookieParser()); | 60 | +// app.use(cookieParser()); |
| 61 | -app.use(express.static(path.join(__dirname, 'public'))); | 61 | +// app.use(express.static(path.join(__dirname, 'public'))); |
| 62 | 62 | ||
| 63 | -app.use('/', indexRouter); | 63 | +// app.use('/', indexRouter); |
| 64 | -app.use('/users', usersRouter); | 64 | +// app.use('/users', usersRouter); |
| 65 | 65 | ||
| 66 | -// catch 404 and forward to error handler | 66 | +// // catch 404 and forward to error handler |
| 67 | -app.use(function (req, res, next) { | 67 | +// app.use(function (req, res, next) { |
| 68 | - next(createError(404)); | 68 | +// next(createError(404)); |
| 69 | -}); | 69 | +// }); |
| 70 | 70 | ||
| 71 | -// error handler | 71 | +// // error handler |
| 72 | -app.use(function (err, req, res, next) { | 72 | +// app.use(function (err, req, res, next) { |
| 73 | - // set locals, only providing error in development | 73 | +// // set locals, only providing error in development |
| 74 | - res.locals.message = err.message; | 74 | +// res.locals.message = err.message; |
| 75 | - res.locals.error = req.app.get('env') === 'development' ? err : {}; | 75 | +// res.locals.error = req.app.get('env') === 'development' ? err : {}; |
| 76 | 76 | ||
| 77 | - // render the error page | 77 | +// // render the error page |
| 78 | - res.status(err.status || 500); | 78 | +// res.status(err.status || 500); |
| 79 | - res.render('error'); | 79 | +// res.render('error'); |
| 80 | -}); | 80 | +// }); |
| 81 | 81 | ||
| 82 | +// module.exports = app; | ||
| 82 | 83 | ||
| 83 | - | ||
| 84 | - | ||
| 85 | -module.exports = app; | ||
| 86 | - | ||
| 87 | -//유저 로그인할때 모든 여행지에 대한 정보를 DB에서 싹다 불러옴 페이지 렌더링할때 data 뿌려줌 | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 84 | +// //유저 로그인할때 모든 여행지에 대한 정보를 DB에서 싹다 불러옴 페이지 렌더링할때 data 뿌려줌 | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| 1 | const express = require('express') | 1 | const express = require('express') |
| 2 | const path = require("path") | 2 | const path = require("path") |
| 3 | +const mongodb = require('mongodb'); | ||
| 4 | +const MongoClient = mongodb.MongoClient; | ||
| 3 | 5 | ||
| 4 | var app = express() | 6 | var app = express() |
| 5 | 7 | ||
| 6 | const PORT = 1697; | 8 | const PORT = 1697; |
| 9 | +const url = 'mongodb://mongo:27017'; | ||
| 10 | +var db; | ||
| 11 | +app.use(express.urlencoded({ extended: true })); | ||
| 7 | 12 | ||
| 8 | app.use("/public", express.static('./public')); | 13 | app.use("/public", express.static('./public')); |
| 9 | 14 | ||
| ... | @@ -11,4 +16,19 @@ app.get("/*", (req, res) => { | ... | @@ -11,4 +16,19 @@ app.get("/*", (req, res) => { |
| 11 | res.sendFile(path.join(__dirname, "./public/index.html")) | 16 | res.sendFile(path.join(__dirname, "./public/index.html")) |
| 12 | }) | 17 | }) |
| 13 | 18 | ||
| 14 | -var serv = app.listen(PORT, () => console.log(`Serveur lauched on port ${PORT}`)) | 19 | +app.get('/festivalList', (req, res) => { // localhost:3000/festivalList 입력하면 list.ejs에 저장한 형식대로 정보 불러와짐 |
| 20 | + //디비에 저장된 festivals 라는 collection안의 데이터(제목 또는 내용 등)를 꺼내기 | ||
| 21 | + db.collection('festivals').find().toArray((err, rslt) => { //DB에서 데이터를 찾음 festivals라는 collection안의 데이터를 꺼내게 됨 | ||
| 22 | + if (err) throw err; | ||
| 23 | + console.log(rslt); | ||
| 24 | + res.render('list.ejs', { posts: rslt }); // 찾은 데이터를 ejs 파일에 넣음 | ||
| 25 | + }); | ||
| 26 | +}); | ||
| 27 | + | ||
| 28 | +MongoClient.connect(url, (error, client) => { // 서버열때 url 사용 mongoDB와 연결시키기 | ||
| 29 | + if (error) return console.log(error); | ||
| 30 | + db = client.db('myFirstDatabase'); | ||
| 31 | + app.listen(PORT, () => { | ||
| 32 | + console.log(`Server lauched on port ${PORT}`); | ||
| 33 | + }); | ||
| 34 | +}); | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -5,10 +5,9 @@ | ... | @@ -5,10 +5,9 @@ |
| 5 | import Article from './Articles.svelte'; | 5 | import Article from './Articles.svelte'; |
| 6 | import { AllFestas } from './Stores/AllFestas'; | 6 | import { AllFestas } from './Stores/AllFestas'; |
| 7 | import jQuery from 'jquery'; | 7 | import jQuery from 'jquery'; |
| 8 | - import { DisplayedFestas } from './Stores/DisplayedFestas'; | ||
| 9 | 8 | ||
| 10 | function LoadFestas() { | 9 | function LoadFestas() { |
| 11 | - let url = "http://api.visitkorea.or.kr/openapi/service/rest/KorService/areaBasedList?ServiceKey=2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D&contentTypeId=15&areaCode=&sigunguCode=&cat1=&cat2=&cat3=&listYN=Y&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&arrange=A&numOfRows=12&pageNo=1&_type=json"; | 10 | + let url = "/festivalList"; |
| 12 | jQuery.getJSON(url, (json) => { | 11 | jQuery.getJSON(url, (json) => { |
| 13 | AllFestas.set(json.response.body.items.item); | 12 | AllFestas.set(json.response.body.items.item); |
| 14 | }); | 13 | }); | ... | ... |
-
Please register or login to post a comment