Junhyuyk Seo

Optimize for deployment

1 +%2FsBWti235XX%2Fg1%2FqBZfiNQ6A%2BJmF3WL%2FboaNqJH4v3eWic59SiHc6W5vgZKU7Hjocj%2BAntIqHfhXOpmE5CpAFw%3D%3D
...\ No newline at end of file ...\ No newline at end of file
1 +2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D
...\ No newline at end of file ...\ No newline at end of file
...@@ -14,4 +14,4 @@ RUN npm install ...@@ -14,4 +14,4 @@ RUN npm install
14 COPY ./ ./ 14 COPY ./ ./
15 15
16 #start application 16 #start application
17 -CMD [ "node", "server.js" ]
...\ No newline at end of file ...\ No newline at end of file
17 +CMD [ "npm", "start" ]
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -24,5 +24,4 @@ const festivalSchema = new Schema({ ...@@ -24,5 +24,4 @@ const festivalSchema = new Schema({
24 versionKey: false 24 versionKey: false
25 }); 25 });
26 26
27 -
28 module.exports = mongoose.model('Festival',festivalSchema); 27 module.exports = mongoose.model('Festival',festivalSchema);
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
2 "name": "REST-API", 2 "name": "REST-API",
3 "version": "1.0.0", 3 "version": "1.0.0",
4 "description": "", 4 "description": "",
5 - "main": "index.js", 5 + "main": "server.js",
6 "scripts": { 6 "scripts": {
7 - "test": "echo \"Error: no test specified\" && exit 1" 7 + "start": "node server"
8 }, 8 },
9 "keywords": [], 9 "keywords": [],
10 "author": "", 10 "author": "",
......
...@@ -2,14 +2,12 @@ const mongoose = require('mongoose'); ...@@ -2,14 +2,12 @@ const mongoose = require('mongoose');
2 // const db = require('mongodb'); 2 // const db = require('mongodb');
3 const Festival = require('./models/Festival'); 3 const Festival = require('./models/Festival');
4 const request = require('request-promise-native'); 4 const request = require('request-promise-native');
5 +const fs = require('fs');
5 6
6 const url = 'mongodb://mongo:27017'; 7 const url = 'mongodb://mongo:27017';
8 +const ServiceKey = fs.readFileSync('./ServiceKey/festival.txt', 'utf-8');
9 +const WeatherServiceKey = fs.readFileSync('./ServiceKey/weather.txt', 'utf-8');
7 10
8 -const ServiceKey = '3zrQDvoNwUV9Se%2BHZv8DjCCNWRGJisQ7jjHP6LsbJqoRQ2cJpQKrHUGC4uslgXSVO9Dzb06BSC3kp9BunvIPSw%3D%3D';
9 -const ServiceKey2 ='%2FGjtI8kwZeJTzJm%2BxUxz%2Bjh15wnmV3rwFuRvrq3oRSqyklfiZfbUaqmsG0McVPJMdXSUYetGaCXl0ZkbfMI0BQ%3D%3D'
10 -const ServiceKey3 ='%2FsBWti235XX%2Fg1%2FqBZfiNQ6A%2BJmF3WL%2FboaNqJH4v3eWic59SiHc6W5vgZKU7Hjocj%2BAntIqHfhXOpmE5CpAFw%3D%3D'
11 -
12 -const WeatherServiceKey = '2lFkvQJYgzOOhwUKiUt8aZVNpd1PpBOf%2FfMNW17cl25DE0GUEDddeR9iGnuSUpggjUoIUgamfhcvnKQ3eH1dAw%3D%3D';
13 const COORDINATES = require('./coordinates')['COORDINATES']; 11 const COORDINATES = require('./coordinates')['COORDINATES'];
14 const DISTRICT = [ 12 const DISTRICT = [
15 "서울특별시", "부산광역시", "울산광역시", "대구광역시", "대전광역시", 13 "서울특별시", "부산광역시", "울산광역시", "대구광역시", "대전광역시",
...@@ -49,9 +47,18 @@ mongoose.connect(url,(err)=>{ ...@@ -49,9 +47,18 @@ mongoose.connect(url,(err)=>{
49 if(err) { 47 if(err) {
50 console.log(err); 48 console.log(err);
51 } else { 49 } else {
50 +
51 + mongoose.connection.db.listCollections().toArray(async (err, collection) => {
52 + if(!collection.includes('festivals')) {
53 + await mongoose.connection.db.createCollection("festivals");
54 + }
55 + });
56 +
57 +
52 mongoose.connection.db.dropCollection('festivals',function(err, result) { 58 mongoose.connection.db.dropCollection('festivals',function(err, result) {
53 if(err) { 59 if(err) {
54 console.log(err + "Reset Failed!"); 60 console.log(err + "Reset Failed!");
61 + writeDB();
55 } else { 62 } else {
56 console.log(result + "Reset Success!"); 63 console.log(result + "Reset Success!");
57 64
...@@ -59,7 +66,7 @@ mongoose.connect(url,(err)=>{ ...@@ -59,7 +66,7 @@ mongoose.connect(url,(err)=>{
59 let options = { 66 let options = {
60 'method': 'GET', 67 'method': 'GET',
61 'url' : 'http://api.visitkorea.or.kr/openapi/service/rest/KorService/areaBasedList' 68 'url' : 'http://api.visitkorea.or.kr/openapi/service/rest/KorService/areaBasedList'
62 - + '?ServiceKey=' + ServiceKey2 69 + + '?ServiceKey=' + ServiceKey
63 + '&contentTypeId=15&areaCode=&sigunguCode=&cat1=&cat2=&cat3=&listYN=Y&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&arrange=C&numOfRows=12' 70 + '&contentTypeId=15&areaCode=&sigunguCode=&cat1=&cat2=&cat3=&listYN=Y&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&arrange=C&numOfRows=12'
64 + '&pageNo='+ i 71 + '&pageNo='+ i
65 + '&_type=json', 72 + '&_type=json',
...@@ -79,7 +86,7 @@ mongoose.connect(url,(err)=>{ ...@@ -79,7 +86,7 @@ mongoose.connect(url,(err)=>{
79 'public': { 86 'public': {
80 'method': 'GET', 87 'method': 'GET',
81 'url': 'http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailCommon?' 88 'url': 'http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailCommon?'
82 - + 'ServiceKey=' + ServiceKey2 89 + + 'ServiceKey=' + ServiceKey
83 + '&contentTypeId=' + '15' 90 + '&contentTypeId=' + '15'
84 + '&contentId=' + item['contentid'] 91 + '&contentId=' + item['contentid']
85 + '&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&defaultYN=Y&firstImageYN=Y&areacodeYN=Y&catcodeYN=Y&addrinfoYN=Y&mapinfoYN=Y&overviewYN=Y&transGuideYN=Y&_type=json', 92 + '&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&defaultYN=Y&firstImageYN=Y&areacodeYN=Y&catcodeYN=Y&addrinfoYN=Y&mapinfoYN=Y&overviewYN=Y&transGuideYN=Y&_type=json',
...@@ -88,7 +95,7 @@ mongoose.connect(url,(err)=>{ ...@@ -88,7 +95,7 @@ mongoose.connect(url,(err)=>{
88 'detail': { 95 'detail': {
89 'method': 'GET', 96 'method': 'GET',
90 'url': 'http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailIntro?' 97 'url': 'http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailIntro?'
91 - + 'ServiceKey=' + ServiceKey2 98 + + 'ServiceKey=' + ServiceKey
92 + '&contentTypeId=' + '15' 99 + '&contentTypeId=' + '15'
93 + '&contentId=' + item['contentid'] 100 + '&contentId=' + item['contentid']
94 + '&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&introYN=Y&_type=json', 101 + '&MobileOS=ETC&MobileApp=TourAPI3.0_Guide&introYN=Y&_type=json',
......
...@@ -11,4 +11,6 @@ services: ...@@ -11,4 +11,6 @@ services:
11 - "8484:8484" 11 - "8484:8484"
12 12
13 apihandler: 13 apihandler:
14 - build: ./TFT_API/
...\ No newline at end of file ...\ No newline at end of file
14 + build: ./TFT_API/
15 + volumes:
16 + - ./ServiceKey:/app/ServiceKey
...\ No newline at end of file ...\ No newline at end of file
......