clothes.js
2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
let express = require('express');
let bodyParser = require('body-parser');
let mongo = require('mongoose');
let cors = require('cors');
let app = express();
app.use(cors());
const uri = 'mongodb+srv://sjieu17:tjrwls147714@cluster0.lc6pe.mongodb.net/weather_briefing?retryWrites=true&w=majority';
//const uri = 'mongodb+srv://tahmkench:dkrldnsl7@cluster0.vzipl.mongodb.net/?retryWrites=true&w=majority';
let hi = mongo.connect(uri, (err) => {
if (err) {
console.log(err.message);
} else {
console.log('Succesfully Connected!');
}
});
var clothesSchema = new mongo.Schema({
gender: Number,
weather: Number,
top: Array,
bottom:Array
});
var Clothes = mongo.model('clothes', clothesSchema);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ limit: '1gb', extended: false }));
app.post('/api/clothes', (req, res) => {
Clothes.findOne({ gender: req.body.gender, weather: req.body.weather }, (err, clothes) => {
let randt=Math.floor(Math.random()*clothes.top.length);
let randb=Math.floor(Math.random()*clothes.bottom.length);
if (err) return res.status(500).json({ MatchingSuccess: false });
else if (clothes) {
if(req.body.rain==1) return res.status(200).json({top:"../../../../src/img/"+ clothes.top[randt]+".jpg",bottom:"../../../../src/img/"+ clothes.bottom[randb]+".jpg",umbrella:1,top1:clothes.top[randt],bottom1:clothes.bottom[randb]})
else return res.status(200).json({top:"../../../../src/img/"+ clothes.top[randt]+".jpg",bottom:"../../../../src/img/"+ clothes.bottom[randb]+".jpg",umbrella:0,top1:clothes.top[randt],bottom1:clothes.bottom[randb]});
}
else return res.status(404).json({ MatchingSuccess: false });
});
});
app.listen(4000, () => console.log('Server On 4000'));
// var express = require('express');
// var app = express();
// var client_id = 'EaHxnjlhHWNjVnHp2eF9';
// var client_secret = 'gPbFbMUxq_';
// app.get('/search/blog', function (req, res) {
// var api_url = 'https://openapi.naver.com/v1/search/shop.json?query=' + encodeURI(req.query.query); // json 결과
// // var api_url = 'https://openapi.naver.com/v1/search/blog.xml?query=' + encodeURI(req.query.query); // xml 결과
// var request = require('request');
// var options = {
// url: api_url,
// headers: {'X-Naver-Client-Id':client_id, 'X-Naver-Client-Secret': client_secret}
// };
// request.get(options, function (error, response, body) {
// if (!error && response.statusCode == 200) {
// res.writeHead(200, {'Content-Type': 'text/json;charset=utf-8'});
// res.end(body);
// } else {
// res.status(response.statusCode).end();
// console.log('error = ' + response.statusCode);
// }
// });
// });
// app.listen(4000, function () {
// console.log('http://127.0.0.1:3000/search/blog?query=검색어 app listening on port 3000!');
// });
// //