장주현

add papago-api function

1 const express = require('express'); 1 const express = require('express');
2 +const request = require('request');
2 const app = express(); 3 const app = express();
4 +const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt'
5 +const client_id = 'cIZBOTfISMHEyygh_NHp';
6 +const client_secret = '8D32UNGgYp';
3 const PORT = process.env.PORT || 3000; 7 const PORT = process.env.PORT || 3000;
4 8
5 //const indexRoute = require("./routes/index"); 9 //const indexRoute = require("./routes/index");
...@@ -13,10 +17,30 @@ app.use(express.static(__dirname + '/public')); ...@@ -13,10 +17,30 @@ app.use(express.static(__dirname + '/public'));
13 app.get('/', function(req, res){ 17 app.get('/', function(req, res){
14 //res.send('hello world'); 18 //res.send('hello world');
15 res.render('index'); 19 res.render('index');
20 +
16 }); 21 });
17 22
18 //app.use('/', indexRoute); 23 //app.use('/', indexRoute);
19 24
20 app.listen(PORT, function(){ 25 app.listen(PORT, function(){
21 console.log('listen',PORT); 26 console.log('listen',PORT);
22 -});
...\ No newline at end of file ...\ No newline at end of file
27 +});
28 +
29 +function trans(message, totrans){
30 + request.post(
31 + {
32 + url: PAPAGO_URL,
33 + headers: {
34 + 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
35 + 'X-Naver-Client-Id': `${PAPAGO_ID}`,
36 + 'X-Naver-Client-Secret': `${PAPAGO_SECRET}`
37 + },
38 + body: 'source=ko&target=en&text=' + message,
39 + json:true
40 + },(error, response, body) => {
41 + if(!error && response.statusCode == 200) {
42 + console.log(body.message);
43 + totrans = body.message.result.translatedText;
44 + }
45 + });
46 +}
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 // iframe을 넣은 element를 안보이게 한다. 17 // iframe을 넣은 element를 안보이게 한다.
18 element_wrap.style.display = 'none'; 18 element_wrap.style.display = 'none';
19 } 19 }
20 - 20 +
21 function sample3_execDaumPostcode() { 21 function sample3_execDaumPostcode() {
22 // 현재 scroll 위치를 저장해놓는다. 22 // 현재 scroll 위치를 저장해놓는다.
23 var currentScroll = Math.max(document.body.scrollTop, document.documentElement.scrollTop); 23 var currentScroll = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
......
...@@ -3,6 +3,7 @@ const router = express.Router(); ...@@ -3,6 +3,7 @@ const router = express.Router();
3 3
4 router.get('/', function(req, res){ 4 router.get('/', function(req, res){
5 res.render('index'); 5 res.render('index');
6 + console.log("trtt")
6 }); 7 });
7 8
8 module.exports = router; 9 module.exports = router;
...\ No newline at end of file ...\ No newline at end of file
......