Showing
3 changed files
with
76 additions
and
13 deletions
No preview for this file type
1 | let express = require('express'); | 1 | let express = require('express'); |
2 | let bodyParser = require('body-parser'); | 2 | let bodyParser = require('body-parser'); |
3 | let mongoose = require('mongoose'); | 3 | let mongoose = require('mongoose'); |
4 | - | 4 | +let nx,ny; |
5 | let app = express(); | 5 | let app = express(); |
6 | +const cors=require('cors'); | ||
7 | +app.use(cors); | ||
8 | + | ||
6 | let logid=null; | 9 | let logid=null; |
7 | const uri = 'mongodb+srv://sjieu17:tjrwls147714@cluster0.lc6pe.mongodb.net/weather_briefing?retryWrites=true&w=majority'; | 10 | const uri = 'mongodb+srv://sjieu17:tjrwls147714@cluster0.lc6pe.mongodb.net/weather_briefing?retryWrites=true&w=majority'; |
8 | let db = mongoose.connect(uri, (err) => { | 11 | let db = mongoose.connect(uri, (err) => { |
... | @@ -12,12 +15,14 @@ let db = mongoose.connect(uri, (err) => { | ... | @@ -12,12 +15,14 @@ let db = mongoose.connect(uri, (err) => { |
12 | console.log('Succesfully Connected!'); | 15 | console.log('Succesfully Connected!'); |
13 | } | 16 | } |
14 | }); | 17 | }); |
15 | - | 18 | +//생년월일을 인자로 추가 |
16 | var UserSchema = new mongoose.Schema({ | 19 | var UserSchema = new mongoose.Schema({ |
17 | name: String, | 20 | name: String, |
18 | id: String, | 21 | id: String, |
19 | password: String, | 22 | password: String, |
20 | - gender:Number | 23 | + gender:String, |
24 | + //nx:String, | ||
25 | + //ny:String | ||
21 | }); | 26 | }); |
22 | 27 | ||
23 | var Users = mongoose.model('users', UserSchema); | 28 | var Users = mongoose.model('users', UserSchema); |
... | @@ -25,7 +30,7 @@ var Users = mongoose.model('users', UserSchema); | ... | @@ -25,7 +30,7 @@ var Users = mongoose.model('users', UserSchema); |
25 | app.use(bodyParser.json()); | 30 | app.use(bodyParser.json()); |
26 | app.use(bodyParser.urlencoded({ limit: '1gb', extended: false })); | 31 | app.use(bodyParser.urlencoded({ limit: '1gb', extended: false })); |
27 | 32 | ||
28 | -app.post('/signup', (req, res) => { | 33 | +app.post('/api/register', (req, res) => { |
29 | Users.findOne({ id: req.body.id, password: req.body.password }, (err, user) => { | 34 | Users.findOne({ id: req.body.id, password: req.body.password }, (err, user) => { |
30 | if (err) return res.status(500).json({ message: '에러가 발생하였습니다.' }); | 35 | if (err) return res.status(500).json({ message: '에러가 발생하였습니다.' }); |
31 | else if (user){ | 36 | else if (user){ |
... | @@ -35,19 +40,18 @@ app.post('/signup', (req, res) => { | ... | @@ -35,19 +40,18 @@ app.post('/signup', (req, res) => { |
35 | var new_user = new Users(req.body); | 40 | var new_user = new Users(req.body); |
36 | 41 | ||
37 | new_user.save((err) => { | 42 | new_user.save((err) => { |
38 | - if (err) return res.status(500).json({ message: '회원가입에 실패하였습니다.' }); | 43 | + if (err) return res.status(500).json({ message: '회원가입에 실패하였습니다.', success: false, err }); |
39 | - else return res.status(200).json({ message: '회원가입이 완료되었습니다.', data: new_user }); | 44 | + else return res.status(200).json({ message: '회원가입이 완료되었습니다.', success: true }); |
40 | }); | 45 | }); |
41 | } | 46 | } |
42 | }); | 47 | }); |
43 | - | ||
44 | }); | 48 | }); |
45 | 49 | ||
46 | -app.post('/signin', (req, res) => { | 50 | +app.post('/login', (req, res) => { |
47 | Users.findOne({ id: req.body.id, password: req.body.password }, (err, user) => { | 51 | Users.findOne({ id: req.body.id, password: req.body.password }, (err, user) => { |
48 | if (err) return res.status(500).json({ message: '에러가 발생하였습니다.' }); | 52 | if (err) return res.status(500).json({ message: '에러가 발생하였습니다.' }); |
49 | else if (user){ | 53 | else if (user){ |
50 | - logid={id:user.id,password:user.password,name:user.name,gender:user.gender}; | 54 | + logid={id:user.id,password:user.password,name:user.name,gender:user.gender,address1:user.address1,address2:user.address2,address3:user.address3}; |
51 | return res.status(200).json({ message: '로그인 되었습니다.', data: user }); | 55 | return res.status(200).json({ message: '로그인 되었습니다.', data: user }); |
52 | } | 56 | } |
53 | else return res.status(404).json({ message: '아이디와 비밀번호를 다시 확인해주세요.' }); | 57 | else return res.status(404).json({ message: '아이디와 비밀번호를 다시 확인해주세요.' }); |
... | @@ -57,4 +61,17 @@ app.post('/logout',(req,res)=>{ | ... | @@ -57,4 +61,17 @@ app.post('/logout',(req,res)=>{ |
57 | logid=null; | 61 | logid=null; |
58 | res.send('로그아웃 되었습니다.'); | 62 | res.send('로그아웃 되었습니다.'); |
59 | }); | 63 | }); |
64 | +// const xlsx=require('xlsx'); | ||
65 | +// const excel=xlsx.readFile('location(x,y).xlsx'); | ||
66 | +// const sheet=excel.SheetNames[0]; | ||
67 | +// const first=excel.Sheets[sheet]; | ||
68 | +// const jsonData=xlsx.utils.sheet_to_json(first,{defval:""}); | ||
69 | +// jsonData.findOne({address1:logid.address1,address2:logid.address2,address3:logid.address3},(err,user)=>{ | ||
70 | +// if (err) return console.log("일치하는 주소가 없습니다."); | ||
71 | +// else if(user){ | ||
72 | +// tmp=Object.values(user); | ||
73 | +// nx=tmp[5]; | ||
74 | +// ny=tmp[6]; | ||
75 | +// } | ||
76 | +// }); | ||
60 | app.listen(4000, () => console.log('Server On 4000')); | 77 | app.listen(4000, () => console.log('Server On 4000')); |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | var request = require('request'); | 1 | var request = require('request'); |
2 | + | ||
3 | + | ||
4 | + | ||
5 | +//nx,ny구하기 | ||
2 | const xlsx=require('xlsx') | 6 | const xlsx=require('xlsx') |
3 | const excel=xlsx.readFile('location(x,y).xlsx'); | 7 | const excel=xlsx.readFile('location(x,y).xlsx'); |
4 | const sheet=excel.SheetNames[0]; | 8 | const sheet=excel.SheetNames[0]; |
5 | const first=excel.Sheets[sheet]; | 9 | const first=excel.Sheets[sheet]; |
6 | const jsonData=xlsx.utils.sheet_to_json(first,{defval:""}); | 10 | const jsonData=xlsx.utils.sheet_to_json(first,{defval:""}); |
7 | -//jsonData.find() 여기서 server.js의 logid의 address123을 입력받아 이 것을 jsonData에서 찾고 싶습니다. nx와 ny에 대입 | ||
8 | let nx,ny; | 11 | let nx,ny; |
12 | +app.post('/address', (req, res) => { | ||
13 | + let i=0; | ||
14 | + while(i<3788){ | ||
15 | + if(jsonData[i].address1==req.address1 && jsonData[i].address2==req.address2 && jsonData[i].address3==req.address3){ | ||
16 | + nx=jsonData[i].nx; | ||
17 | + ny=jsonData[i].ny; | ||
18 | + break; | ||
19 | + } | ||
20 | + i+=1; | ||
21 | + } | ||
22 | + res.send("좌표는 ",nx,ny,"입니다."); | ||
23 | +}); | ||
24 | + | ||
25 | + | ||
26 | +//jsonData.find() 여기서 server.js의 logid의 address123을 입력받아 이 것을 찾음 싶습니다. nx와 ny에 대입 | ||
27 | + | ||
28 | + | ||
29 | + | ||
30 | + | ||
31 | + | ||
32 | + | ||
33 | + | ||
34 | +//오늘의 날짜 구하기 | ||
35 | +let today=new Date(); | ||
36 | +let CurDay=today.getFullYear().toString(); | ||
37 | +if(today.getMonth()<9){ | ||
38 | + CurDay+="0"+(today.getMonth()+1).toString(); | ||
39 | +} | ||
40 | +else{ | ||
41 | + CurDay+=(today.getMonth()+1).toString(); | ||
42 | +} | ||
43 | +if(today.getDate()<10){ | ||
44 | + CurDay+="0"+today.getDate().toString(); | ||
45 | +} | ||
46 | +else{ | ||
47 | + CurDay+=today.getDate().toString(); | ||
48 | +} | ||
49 | + | ||
50 | + | ||
9 | 51 | ||
52 | +//입력받기 | ||
10 | var url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst'; | 53 | var url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst'; |
11 | var queryParams = '?' + encodeURIComponent('serviceKey') + '=3OcUyvx97Vx2YikiZ9IHyRQ6suapku7Xn8VlefQKQWrGIFOGaejhbevwagcubdHfSiQAqJwCV5lyIutw0%2BsppA%3D%3D'; /* Service Key*/ | 54 | var queryParams = '?' + encodeURIComponent('serviceKey') + '=3OcUyvx97Vx2YikiZ9IHyRQ6suapku7Xn8VlefQKQWrGIFOGaejhbevwagcubdHfSiQAqJwCV5lyIutw0%2BsppA%3D%3D'; /* Service Key*/ |
12 | queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */ | 55 | queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */ |
13 | queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('1000'); /* */ | 56 | queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('1000'); /* */ |
14 | queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('JSON'); /* */ | 57 | queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('JSON'); /* */ |
15 | -queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent('20220521'); /* */ | 58 | +queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent(CurDay); /* */ |
16 | queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('0200'); /* */ | 59 | queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('0200'); /* */ |
17 | -queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent('62'); /*nx*/ | 60 | +queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent(nx.toString()); /*nx*/ |
18 | -queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent('120'); /*ny*/ | 61 | +queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent(ny.toString()); /*ny*/ |
19 | 62 | ||
20 | request({ | 63 | request({ |
21 | url: url + queryParams, | 64 | url: url + queryParams, |
... | @@ -38,4 +81,7 @@ request({ | ... | @@ -38,4 +81,7 @@ request({ |
38 | fcstValue:list.fcstValue | 81 | fcstValue:list.fcstValue |
39 | })); | 82 | })); |
40 | console.log(temp2); | 83 | console.log(temp2); |
84 | +}); | ||
85 | +app.post('/mainpage', (req, res) => { | ||
86 | + | ||
41 | }); | 87 | }); |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment