장주현

post from index.ejs

1 const express = require('express'); 1 const express = require('express');
2 const request = require('request'); 2 const request = require('request');
3 +const fs = require('fs');
4 +const bodyParser = require('body-parser');
3 const app = express(); 5 const app = express();
4 const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt' 6 const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt'
5 -const client_id = 'cIZBOTfISMHEyygh_NHp'; 7 +const PAPAGO_ID = 'cIZBOTfISMHEyygh_NHp';
6 -const client_secret = '8D32UNGgYp'; 8 +const PAPAGO_SECRET = '8D32UNGgYp';
7 const PORT = process.env.PORT || 3000; 9 const PORT = process.env.PORT || 3000;
8 10
9 //const indexRoute = require("./routes/index"); 11 //const indexRoute = require("./routes/index");
10 - 12 +app.use(bodyParser.urlencoded({extended: true}));
11 app.set('views', __dirname + '/views'); 13 app.set('views', __dirname + '/views');
12 app.set('view engine', 'ejs'); 14 app.set('view engine', 'ejs');
13 app.use(express.static(__dirname + '/public')); 15 app.use(express.static(__dirname + '/public'));
14 //var postcode = require(postcode.v2.html); 16 //var postcode = require(postcode.v2.html);
15 //const fs = require('filesystem') 17 //const fs = require('filesystem')
18 +var addressK, addressE;
19 +var detailaddressK, detailaddressE;
20 +var extraaddressK, extraaddressE;
21 +var zipcode;
16 22
17 app.get('/', function(req, res){ 23 app.get('/', function(req, res){
18 //res.send('hello world'); 24 //res.send('hello world');
...@@ -20,8 +26,31 @@ app.use(express.static(__dirname + '/public')); ...@@ -20,8 +26,31 @@ app.use(express.static(__dirname + '/public'));
20 26
21 }); 27 });
22 28
29 + app.get('/', function(req, res){
30 +
31 +
32 + res.render('index');
33 + });
34 +
23 //app.use('/', indexRoute); 35 //app.use('/', indexRoute);
24 36
37 +app.post('/', function(req,res){
38 + console.log(req.body);
39 + zipcode = req.body.zipcode;
40 + addressK = req.body.addressK;
41 + detailaddressK = req.body.detailaddressK;
42 + extraaddressK = req.body.extraaddressK;
43 + console.log(addressK);
44 + addressE = trans(addressK, detailaddressE);
45 + //trans(detailaddressK, detailaddressE);
46 + //trans(extraaddressK, extraaddressE);
47 + setTimeout(function(){console.log("set: " +detailaddressE)},500);
48 + console.log("address: " + addressE);
49 + console.log("detail: " + detailaddressE);
50 +
51 +});
52 +
53 +
25 app.listen(PORT, function(){ 54 app.listen(PORT, function(){
26 console.log('listen',PORT); 55 console.log('listen',PORT);
27 }); 56 });
...@@ -41,6 +70,8 @@ function trans(message, totrans){ ...@@ -41,6 +70,8 @@ function trans(message, totrans){
41 if(!error && response.statusCode == 200) { 70 if(!error && response.statusCode == 200) {
42 console.log(body.message); 71 console.log(body.message);
43 totrans = body.message.result.translatedText; 72 totrans = body.message.result.translatedText;
73 +
74 + return totrans;
44 } 75 }
45 }); 76 });
46 }; 77 };
...\ No newline at end of file ...\ No newline at end of file
......
1 1
2 2
3 -<form> 3 +<form action="" method="POST">
4 <input type="text" name="zipcode" id="sample3_postcode" placeholder="우편번호"> 4 <input type="text" name="zipcode" id="sample3_postcode" placeholder="우편번호">
5 <input type="button" onclick="sample3_execDaumPostcode()" value="우편번호 찾기"><br> 5 <input type="button" onclick="sample3_execDaumPostcode()" value="우편번호 찾기"><br>
6 <input type="text" name="addressK" id="sample3_address" placeholder="주소"><br> 6 <input type="text" name="addressK" id="sample3_address" placeholder="주소"><br>
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
8 <input type="text" name="extraaddressK" id="sample3_extraAddress" placeholder="참고항목"> 8 <input type="text" name="extraaddressK" id="sample3_extraAddress" placeholder="참고항목">
9 9
10 <p> 사용할 해외 쇼핑몰 선택 후 변환</p> 10 <p> 사용할 해외 쇼핑몰 선택 후 변환</p>
11 - <input type="radio" id="selshop" name="os" value="amazon" checked="checked">Amazon 11 + <input type="radio" name="os" value="amazon" checked="checked">Amazon
12 - <input type="radio" id="selshop" name="os" value="ebay">Ebay 12 + <input type="radio" name="os" value="ebay">Ebay
13 <input type="submit" value="주소 변환"> 13 <input type="submit" value="주소 변환">
14 </form> 14 </form>
15 <p> 사용할 해외 쇼핑몰 선택 후 변환</p> 15 <p> 사용할 해외 쇼핑몰 선택 후 변환</p>
......