오세헌

base source code

Showing 56 changed files with 937 additions and 0 deletions
1 +let express = require('express');
2 +let app = express();
3 +let bodyParser = require('body-parser');
4 +
5 +app.use(bodyParser.urlencoded({ extended: false }));
6 +app.use(bodyParser.json());
7 +
8 +
9 +let books = new Array();
10 +
11 +app.get('/books/:bookId', (req, res) => {
12 + let bookId = req.params.bookId;
13 + console.log(books[bookId]);
14 + res.send(books[bookId]);
15 +});
16 +
17 +/*
18 + * json representation of book object
19 +{
20 + "id" : 2,
21 + "name" : "book2",
22 + "price" : 2000,
23 + "author" : "jin"
24 +}
25 +*/
26 +app.post('/books', (req, res) => {
27 + // Create book information
28 + books[req.body.id] = [req.body.id, req.body.name, req.body.price, req.body.author];
29 + res.send(books[req.body.id]);
30 +})
31 +
32 +app.put('/books', (req, res) => {
33 + // Update book information
34 +
35 +})
36 +
37 +
38 +app.delete('/books/:bookId', (req, res) => {
39 + // Delete book information
40 +
41 +})
42 +let server = app.listen(80);
43 + console.log(books);
1 +{
2 + "name": "assignment01",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "index.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "author": "",
10 + "license": "ISC",
11 + "dependencies": {
12 + "body-parser": "^1.17.1",
13 + "express": "^4.15.2"
14 + }
15 +}
1 +let express = require('express');
2 +let app = express();
3 +let bodyParser = require('body-parser');
4 +let session = require('express-session')
5 +
6 +app.use(session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }}))
7 +app.use(bodyParser.urlencoded({ extended: false }));
8 +app.use(bodyParser.json());
9 +
10 +
11 +let users = new Array();
12 +users[0] = {
13 + "userId" : 0,
14 + "name" : "jin",
15 + "password" : "abc",
16 + "isAdmin" : true
17 +}
18 +
19 +app.put('/login', (req, res) => {
20 + // users 배열에서 찾도록 처리 해야 함
21 + // admin 여부를 확인하여 체크
22 + // req.body.id : ID
23 + // req.body.name : 패스워드
24 +
25 + res.send("Login");
26 +});
27 +
28 +app.put('/logout', (req, res) => {
29 + // Logout
30 + // 세션 유효 여부를 체크하고 세션 Delete
31 + req.session.userId = null;
32 + res.send("LogOut");
33 +
34 +});
35 +
36 +let auth = (req, res, next) => {
37 + // Session Check
38 + // 어드민 여부 체크 필요
39 + if (req.session.userId != null)
40 + next();
41 + else
42 + res.send("Error");
43 +
44 +};
45 +app.get('/user/:userId', auth, (req, res) => {
46 + // get User Information
47 + res.send("OK");
48 +});
49 +
50 +// 사용자 추가 시에 admin 여부도 추가해야 함
51 +
52 +let server = app.listen(80);
1 +{
2 + "name": "assignment02",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "index.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "author": "",
10 + "license": "ISC",
11 + "dependencies": {
12 + "body-parser": "^1.17.1",
13 + "express": "^4.15.2",
14 + "express-session": "^1.15.2"
15 + }
16 +}
1 +var express = require('express');
2 +var app = express();
3 +
4 +app.get('/', function (req, res) {
5 + res.send('hello world');
6 +})
7 +
8 +app.route('/book')
9 + .get(function (req, res) {
10 + res.send('Get a random book');
11 + })
12 + .post(function (req, res) {
13 + res.send('Add a book');
14 + })
15 + .put(function (req, res) {
16 + res.send('Update the book');
17 + });
18 +
19 +
20 +var server = app.listen(23023);
1 +{
2 + "name": "approute",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "index.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "author": "",
10 + "license": "ISC",
11 + "dependencies": {
12 + "express": "^4.15.2"
13 + }
14 +}
1 +var express = require('express');
2 +var app = express();
3 +var birds = require('./birds');
4 +
5 +
6 +app.get('/', function (req, res) {
7 + res.send('hello world');
8 +})
9 +
10 +app.use('/birds',birds);
11 +var server = app.listen(23023);
1 +var express = require('express');
2 +var router = express.Router();
3 +
4 +
5 +router.get('/', function (req, res) {
6 + res.send('Birds home page');
7 +})
8 +router.get('/about', function (req, res) {
9 + res.send('About birds');
10 +});
11 +
12 +module.exports=router;
1 +{
2 + "name": "expressrouter",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "index.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "author": "",
10 + "license": "ISC",
11 + "dependencies": {
12 + "express": "^4.15.2"
13 + }
14 +}
1 +var express = require('express');
2 +var app = express();
3 +app.get('/', function (req, res) {
4 + res.send('Hello World');
5 +})
6 +
7 +var server = app.listen(23023, function () {
8 + var host = server.address().address
9 + var port = server.address().port
10 + console.log("Example app listening at http://%s:%s", host, port)
11 +})
12 +
1 +{
2 + "name": "helloworld",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "index.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "author": "",
10 + "license": "ISC",
11 + "dependencies": {
12 + "express": "^4.15.2"
13 + }
14 +}
1 +var express = require('express');
2 +var app = express();
3 +
4 +app.get('/b', function (req, res, next) {
5 + console.log('the response will be sent by the next function ...')
6 + next()
7 +}, function (req, res) {
8 + res.send('Hello from B!')
9 +})
10 +
11 +var cb0 = function (req, res, next) {
12 + console.log("call by cb0");
13 + next()
14 +}
15 +var cb1 = function (req, res, next) {
16 + console.log("call by cb1");
17 + res.send('Hello from C!')
18 +}
19 +app.get('/c', [cb0, cb1])
20 +
21 +var server = app.listen(23023);
1 +{
2 + "name": "multiplehandler",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "index.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "author": "",
10 + "license": "ISC",
11 + "dependencies": {
12 + "express": "^4.15.2"
13 + }
14 +}
1 +var express = require('express');
2 +var app = express();
3 +
4 +app.set('view engine', 'ejs');
5 +app.set('views', 'views');
6 +
7 +app.get('/', function(req, res) {
8 + res.render('index', { title: 'OSS Page' });
9 +});
10 +
11 +var server = app.listen(23023);
1 +{
2 + "name": "render",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "index.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "author": "",
10 + "license": "ISC",
11 + "dependencies": {
12 + "ejs": "^2.5.6",
13 + "express": "^4.15.2"
14 + }
15 +}
1 +var express = require('express');
2 +var app = express();
3 +
4 +app.get('/users/:userId/books/:bookId', function (req, res) {
5 + res.send(req.params);
6 +})
7 +
8 +var server = app.listen(23023);
1 +{
2 + "name": "routeparameter",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "index.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "author": "",
10 + "license": "ISC",
11 + "dependencies": {
12 + "express": "^4.15.2"
13 + }
14 +}
1 +var express = require('express');
2 +var app = express();
3 +
4 +// The routing path matches requests to /about
5 +app.get('/about', function (req, res) {
6 + res.send('about')
7 +})
8 +
9 +// The routing path matches requests to /random.text
10 +app.get('/random.text', function (req, res) {
11 + res.send('random.text')
12 +})
13 +
14 +// This route path matches abcd, abxcd, abRANDOMcd, ab123cd, and so on.
15 +app.get('/ab*cd', function (req, res) {
16 + res.send('ab*cd')
17 +})
18 +
19 +var server = app.listen(23023);
1 +{
2 + "name": "routingpath",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "index.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "author": "",
10 + "license": "ISC",
11 + "dependencies": {
12 + "express": "^4.15.2"
13 + }
14 +}
1 +var express = require('express');
2 +var app = express();
3 +
4 +var session = require('express-session')
5 +
6 +app.use(session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }}))
7 +
8 +
9 +
10 +app.get('/', function(req, res, next) {
11 + var sess = req.session;
12 + console.log(req.session);
13 + if (sess.views) {
14 + sess.views++;
15 + res.send("session Views " + sess.views);
16 + res.send();
17 + } else {
18 + req.session.views = 1;
19 + res.send("welcome to the session demo. refresh!");
20 + res.end();
21 + }
22 +});
23 +
24 +var server = app.listen(23023);
1 +{
2 + "name": "session",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "index.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "author": "",
10 + "license": "ISC",
11 + "dependencies": {
12 + "express": "^4.15.2",
13 + "express-session": "^1.15.2"
14 + }
15 +}
1 +var express = require('express');
2 +var app = express();
3 +
4 +app.get('/', function (req, res) {
5 + res.send('hello world');
6 +})
7 +
8 +var server = app.listen(23023);
1 +{
2 + "name": "simplerouting",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "index.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "author": "",
10 + "license": "ISC",
11 + "dependencies": {
12 + "express": "^4.15.2"
13 + }
14 +}
1 +var express = require('express');
2 +var app = express();
3 +
4 +app.all('/', function (req, res, next) {
5 + console.log('Accessing the secret section ...')
6 + next() // pass control to the next handler
7 +})
8 +
9 +app.get('/', function (req, res) {
10 + res.send('hello world');
11 +})
12 +
13 +app.post('/', function (req, res) {
14 + res.send('POST request to the homepage')
15 +})
16 +
17 +var server = app.listen(23023);
1 +{
2 + "name": "specialrouting",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "index.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "author": "",
10 + "license": "ISC",
11 + "dependencies": {
12 + "express": "^4.15.2"
13 + }
14 +}
1 +var express = require('express');
2 +var app = express();
3 +app.use(express.static('public'));
4 +app.get('/', function (req, res) {
5 + res.send('Hello World');
6 +})
7 +var server = app.listen(23023);
1 +{
2 + "name": "staticfiles",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "index.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "author": "",
10 + "license": "ISC",
11 + "dependencies": {
12 + "express": "^4.15.2"
13 + }
14 +}
1 +// 모듈을 읽어 들입니다.
2 +const request = require('request');
3 +// 요청을 위한 상수를 선언합니다: TOKEN은 자신의 것을 입력해주세요.
4 +const TARGET_URL = 'https://notify-api.line.me/api/notify';
5 +const TOKEN = '///채워주세요///';
6 +// 요청합니다.
7 +request.post(
8 + {
9 + url: TARGET_URL,
10 + headers: {
11 + 'Authorization': `Bearer ${TOKEN}`
12 + },
13 + form: {
14 + message: '안녕하세요. LINE Notify 테스트입니다.',
15 + stickerPackageId: 1,
16 + stickerId: 1
17 + }
18 + },(error, response, body) => {
19 + console.log(body)
20 + });
1 +{
2 + "name": "notify",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "app.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "author": "",
10 + "license": "ISC",
11 + "dependencies": {
12 + "request": "^2.88.2"
13 + }
14 +}
1 +const request = require('request');
2 +const TARGET_URL = 'https://api.line.me/v2/bot/message/push'
3 +const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast'
4 +const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast'
5 +const TOKEN = '채널 토큰으로 교체'
6 +const USER_ID = '사용자의 ID, 메세지 수신 시에 확인할 수 있음'
7 +
8 +// Single User
9 +// request.post(
10 +// {
11 +// url: TARGET_URL,
12 +// headers: {
13 +// 'Authorization': `Bearer ${TOKEN}`
14 +// },
15 +// json: {
16 +// "to": `${USER_ID}`,
17 +// "messages":[
18 +// {
19 +// "type":"text",
20 +// "text":"Hello, user"
21 +// },
22 +// {
23 +// "type":"text",
24 +// "text":"May I help you?"
25 +// }
26 +// ]
27 +// }
28 +// },(error, response, body) => {
29 +// console.log(body)
30 +// });
31 +
32 +
33 +// Multicast User
34 +// request.post(
35 +// {
36 +// url: MULTI_TARGET_URL,
37 +// headers: {
38 +// 'Authorization': `Bearer ${TOKEN}`
39 +// },
40 +// json: {
41 +// "to": [`${USER_ID}`],
42 +// "messages":[
43 +// {
44 +// "type":"text",
45 +// "text":"Hello, user"
46 +// },
47 +// {
48 +// "type":"text",
49 +// "text":"May I help you?"
50 +// }
51 +// ]
52 +// }
53 +// },(error, response, body) => {
54 +// console.log(body)
55 +// });
56 +
57 +
58 +// Broadcast
59 + request.post(
60 + {
61 + url: BROAD_TARGET_URL,
62 + headers: {
63 + 'Authorization': `Bearer ${TOKEN}`
64 + },
65 + json: {
66 + "messages":[
67 + {
68 + "type":"text",
69 + "text":"Hello, user"
70 + },
71 + {
72 + "type":"text",
73 + "text":"May I help you?"
74 + }
75 + ]
76 + }
77 + },(error, response, body) => {
78 + console.log(body)
79 + });
...\ No newline at end of file ...\ No newline at end of file
1 +{
2 + "name": "push",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "app.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "author": "",
10 + "license": "ISC",
11 + "dependencies": {
12 + "request": "^2.88.2"
13 + }
14 +}
1 +var express = require('express');
2 +const request = require('request');
3 +const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
4 +const TOKEN = '채널 토큰으로 변경'
5 +const fs = require('fs');
6 +const path = require('path');
7 +const HTTPS = require('https');
8 +const domain = "도메인 변경"
9 +const sslport = 23023;
10 +
11 +const bodyParser = require('body-parser');
12 +var app = express();
13 +app.use(bodyParser.json());
14 +app.post('/hook', function (req, res) {
15 +
16 + var eventObj = req.body.events[0];
17 + var source = eventObj.source;
18 + var message = eventObj.message;
19 +
20 + // request log
21 + console.log('======================', new Date() ,'======================');
22 + console.log('[request]', req.body);
23 + console.log('[request source] ', eventObj.source);
24 + console.log('[request message]', eventObj.message);
25 +
26 + request.post(
27 + {
28 + url: TARGET_URL,
29 + headers: {
30 + 'Authorization': `Bearer ${TOKEN}`
31 + },
32 + json: {
33 + "replyToken":eventObj.replyToken,
34 + "messages":[
35 + {
36 + "type":"text",
37 + "text":"Hello, user"
38 + },
39 + {
40 + "type":"text",
41 + "text":"May I help you?"
42 + }
43 + ]
44 + }
45 + },(error, response, body) => {
46 + console.log(body)
47 + });
48 +
49 +
50 + res.sendStatus(200);
51 +});
52 +
53 +try {
54 + const option = {
55 + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
56 + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(),
57 + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(),
58 + };
59 +
60 + HTTPS.createServer(option, app).listen(sslport, () => {
61 + console.log(`[HTTPS] Server is started on port ${sslport}`);
62 + });
63 + } catch (error) {
64 + console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
65 + console.log(error);
66 + }
67 +
1 +{
2 + "name": "reply",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "app.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "author": "",
10 + "license": "ISC",
11 + "dependencies": {
12 + "body-parser": "^1.19.0",
13 + "express": "^4.17.1",
14 + "request": "^2.88.2"
15 + }
16 +}
1 +const express = require('express');
2 +const fs = require('fs');
3 +const path = require('path');
4 +const HTTPS = require('https');
5 +
6 +const app = express();
7 +// 본인이 소유한 도메인으로 변경해야 함
8 +// www 붙여야 함
9 +const domain = "www.stagefive.tk"
10 +const sslport = 23023;
11 +
12 +app.get('/', function (req, res) {
13 + res.send('Hello World');
14 +})
15 +
16 +try {
17 + const option = {
18 + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
19 + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(),
20 + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(),
21 + };
22 +
23 + HTTPS.createServer(option, app).listen(sslport, () => {
24 + console.log(`[HTTPS] Server is started on port ${sslport}`);
25 + });
26 +} catch (error) {
27 + console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
28 + console.log(error);
29 +}
30 +
1 +{
2 + "name": "ssl",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "app.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "author": "",
10 + "license": "ISC",
11 + "dependencies": {
12 + "express": "^4.17.1"
13 + }
14 +}
1 +var express = require('express');
2 +const request = require('request');
3 +const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
4 +const TOKEN = '채널 토큰'
5 +const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt'
6 +const PAPAGO_ID = '파파고 ID'
7 +const PAPAGO_SECRET = '파파고 Client Secret'
8 +const fs = require('fs');
9 +const path = require('path');
10 +const HTTPS = require('https');
11 +const domain = "도메인 명"
12 +const sslport = 23023;
13 +const bodyParser = require('body-parser');
14 +var app = express();
15 +app.use(bodyParser.json());
16 +app.post('/hook', function (req, res) {
17 +
18 + var eventObj = req.body.events[0];
19 + var source = eventObj.source;
20 + var message = eventObj.message;
21 +
22 + // request log
23 + console.log('======================', new Date() ,'======================');
24 + console.log('[request]', req.body);
25 + console.log('[request source] ', eventObj.source);
26 + console.log('[request message]', eventObj.message);
27 +
28 + trans(eventObj.replyToken, eventObj.message.text);
29 +
30 +
31 + res.sendStatus(200);
32 +});
33 +
34 +function trans(replyToken, message) {
35 +
36 + request.post(
37 + {
38 + url: PAPAGO_URL,
39 + headers: {
40 + 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
41 + 'X-Naver-Client-Id': `${PAPAGO_ID}`,
42 + 'X-Naver-Client-Secret': `${PAPAGO_SECRET}`
43 + },
44 + body: 'source=ko&target=en&text=' + message,
45 + json:true
46 + },(error, response, body) => {
47 + if(!error && response.statusCode == 200) {
48 + console.log(body.message);
49 + var transMessage = body.message.result.translatedText;
50 + request.post(
51 + {
52 + url: TARGET_URL,
53 + headers: {
54 + 'Authorization': `Bearer ${TOKEN}`
55 + },
56 + json: {
57 + "replyToken":replyToken,
58 + "messages":[
59 + {
60 + "type":"text",
61 + "text":transMessage
62 + }
63 + ]
64 + }
65 + },(error, response, body) => {
66 + console.log(body)
67 + });
68 + }
69 + });
70 +
71 +}
72 +
73 +try {
74 + const option = {
75 + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
76 + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(),
77 + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(),
78 + };
79 +
80 + HTTPS.createServer(option, app).listen(sslport, () => {
81 + console.log(`[HTTPS] Server is started on port ${sslport}`);
82 + });
83 + } catch (error) {
84 + console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
85 + console.log(error);
86 + }
87 +
...\ No newline at end of file ...\ No newline at end of file
1 +{
2 + "name": "trans",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "app.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "author": "",
10 + "license": "ISC",
11 + "dependencies": {
12 + "express": "^4.17.1",
13 + "request": "^2.88.2"
14 + }
15 +}
1 +var express = require('express');
2 +const bodyParser = require('body-parser');
3 +var app = express();
4 +const fs = require('fs');
5 +const path = require('path');
6 +const HTTPS = require('https');
7 +const domain = "도메인 변경 처리"
8 +const sslport = 23023;
9 +
10 +app.use(bodyParser.json());
11 +
12 +app.post('/hook', function (request, response) {
13 +
14 + var eventObj = request.body.events[0];
15 +
16 + // request log
17 + console.log('======================', new Date() ,'======================');
18 +
19 + response.sendStatus(200);
20 +});
21 +
22 +
23 +try {
24 + const option = {
25 + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
26 + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(),
27 + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(),
28 + };
29 +
30 + HTTPS.createServer(option, app).listen(sslport, () => {
31 + console.log(`[HTTPS] Server is started on port ${sslport}`);
32 + });
33 + } catch (error) {
34 + console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
35 + console.log(error);
36 + }
37 +
1 +{
2 + "name": "webhook",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "app.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "author": "",
10 + "license": "ISC",
11 + "dependencies": {
12 + "body-parser": "^1.19.0",
13 + "express": "^4.17.1"
14 + }
15 +}
1 +// 아래 2개의 함수를 모듈로 정의하는 것이 필요함
2 +function add(a,b) {
3 + return a+b;
4 +}
5 +function sub(a,b) {
6 + return a-b;
7 +}
1 +const doSomethingAsync = () => {
2 + return new Promise(resolve => {
3 + setTimeout(() => resolve('I did something'), 3000)
4 + })
5 +}
6 +
7 +// doSomething 함수를 async await 형태로 변경하시오
8 +const doSomething = () => {
9 + doSomethingAsync().then( a => console.log(a))
10 +}
11 +
12 +console.log('Before')
13 +doSomething()
14 +console.log('After')
1 +var events = require('events');
2 +var eventEmitter = new events.EventEmitter();
3 +var connectHandler = function connected() {
4 + console.log('connection successful.');
5 + eventEmitter.emit('data_received');
6 +}
7 +
8 +eventEmitter.on('connection', connectHandler);
9 +
10 +eventEmitter.on('data_received', function(){
11 + console.log('data received successfully.');
12 +});
13 +
14 +eventEmitter.emit('connection');
15 +console.log("Program Ended.");
1 +var events = require('events');
2 +var eventEmitter = new events.EventEmitter();
3 +var listner1 = function listner1() {
4 +console.log('listner1 executed.');
5 +}
6 +var listner2 = function listner2() {
7 +console.log('listner2 executed.');
8 +}
9 +
10 +eventEmitter.addListener('connection', listner1);
11 +eventEmitter.on('connection', listner2);
12 +var eventListeners = require('events').EventEmitter.listenerCount(eventEmitter,'connection');
13 +console.log(eventListeners + " Listner(s) listening to connection event");
14 +
15 +eventEmitter.emit('connection');
16 +eventEmitter.removeListener('connection', listner1);
17 +console.log("Listner1 will not listen now.");
18 +
19 +eventEmitter.emit('connection');
20 +eventListeners = require('events').EventEmitter.listenerCount(eventEmitter,'connection');
21 +console.log(eventListeners + " Listner(s) listening to connection event");
22 +console.log("Program Ended.");