송민석

Modify index.js file

Showing 1 changed file with 16 additions and 84 deletions
1 +
1 const config =require('./config') 2 const config =require('./config')
2 const mongoose = require("mongoose"); 3 const mongoose = require("mongoose");
3 const connect = mongoose.connect(config.url, 4 const connect = mongoose.connect(config.url,
...@@ -9,89 +10,20 @@ const connect = mongoose.connect(config.url, ...@@ -9,89 +10,20 @@ const connect = mongoose.connect(config.url,
9 .catch((err) => console.log(err.message)); 10 .catch((err) => console.log(err.message));
10 11
11 12
12 - const TimeSchema = new mongoose.Schema({ 13 +/*
13 - time: String, 14 +const { MongoClient } = require("mongodb");
14 - prof: String, 15 +const config =require('./config')
15 - credit: Number, 16 +const client = new MongoClient(config.url);
16 - }); 17 +async function run() {
17 - 18 + try {
18 - const SubSchema = new mongoose.Schema({ 19 + await client.connect();
19 - campus: String, 20 + console.log("Connected correctly to server");
20 - college: String, 21 + } catch (err) {
21 - department: String, 22 + console.log(err.stack);
22 - grade: String,
23 - subject: [TimeSchema],
24 - });
25 -
26 - const Timeinfo = mongoose.model('Timeinfo', TimeSchema);
27 - const Subinfo = mongoose.model('Subinfo', SubSchema);
28 -
29 - module.exports = {Timeinfo, Subinfo};
30 -
31 - var express = require('express');
32 -const request = require('request');
33 -const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
34 -const TOKEN = 'KDfacj4wYOewyww1JPcvRZYDz+9UaV/mtjr9jkYiZw2Ywm0NO9R100opUwuRHMzXoTxmstALtM5a6l4Ro8nkjQBOT8HsBsARXeqRt6gaKDb1Hu7FAOmQ6kcKN8qsiwyEdKWDJnqaCB7im3QIiPGqIAdB04t89/1O/w1cDnyilFU='
35 -const fs = require('fs');
36 -const path = require('path');
37 -const HTTPS = require('https');
38 -const domain = "2019102187.osschatbot2022.ml"
39 -const sslport = 23023;
40 -
41 -const bodyParser = require('body-parser');
42 -var app = express();
43 -app.use(bodyParser.json());
44 -app.post('/hook', function (req, res) {
45 -
46 - var eventObj = req.body.events[0];
47 - var source = eventObj.source;
48 - var message = eventObj.message;
49 -
50 - // request log
51 - console.log('======================', new Date() ,'======================');
52 - console.log('[request]', req.body);
53 - console.log('[request source] ', eventObj.source);
54 - console.log('[request message]', eventObj.message);
55 -
56 - request.post(
57 - {
58 - url: TARGET_URL,
59 - headers: {
60 - 'Authorization': `Bearer ${TOKEN}`
61 - },
62 - json: {
63 - "replyToken":eventObj.replyToken,
64 - "messages":[
65 - {
66 - "type":"text",
67 - "text":"Hello, user"
68 - },
69 - {
70 - "type":"text",
71 - "text":"May I help you?"
72 } 23 }
73 - ] 24 + finally {
25 + await client.close();
74 } 26 }
75 - },(error, response, body) => { 27 +}
76 - console.log(body) 28 +run().catch(console.dir);
77 - }); 29 +*/
78 -
79 -
80 - res.sendStatus(200);
81 -});
82 -
83 -try {
84 - const option = {
85 - ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
86 - key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(),
87 - cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(),
88 - };
89 -
90 - HTTPS.createServer(option, app).listen(sslport, () => {
91 - console.log(`[HTTPS] Server is started on port ${sslport}`);
92 - });
93 - } catch (error) {
94 - console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
95 - console.log(error);
96 - }
97 -
...\ No newline at end of file ...\ No newline at end of file
......