-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
30 lines (30 loc) · 1017 Bytes
/
test.js
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
var express = require('express');
var app = express();
require('dotenv').config();
var client_id = process.env.PAPAGO_CLIENT_ID;
var client_secret = process.env.PAPAGO_CLIENT_SECRET;
var query = 'hello';
app.get('/translate', function (req, res) {
var api_url = 'https://openapi.naver.com/v1/papago/n2mt';
var request = require('request');
var options = {
url: api_url,
form: { source: 'en', target: 'ko', text: query },
headers: {
'X-Naver-Client-Id': client_id,
'X-Naver-Client-Secret': client_secret,
},
};
request.post(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(3000, function () {
console.log('http://127.0.0.1:3000/translate app listening on port 3000!');
});