Commit b9338a69 authored by tug's avatar tug

First run my client

parent 73c2e0d8
node_modules/ node_modules/
*.log *.log
_td*
const http = require('http') const http = require('http')
// const tgclient = require('./tgclient')
// const logger = require('./logger')
const { Client } = require('tdl')
const { TDLib } = require('tdl-tdlib-addon')
var path = require('path');
const tgclient = new Client(new TDLib(path.join(__dirname, 'td/build/libtdjson.so')), {
apiId: 234569,
apiHash: 'ee77bf549e61d3de158916126c8ef7dd'
})
tgclient.on('error', console.error)
tgclient.on('update', update => {
console.log('Received update:', update)
})
async function main () {
await tgclient.connectAndLogin()
console.log(await tgclient.invoke({ _: 'getMe' }))
// ...
}
main().catch(console.error)
var myNumber = 1;
const host = '192.168.130.10' const host = '192.168.130.10'
const port = 51000 const port = 51000
...@@ -10,56 +39,91 @@ function notFound(res) { ...@@ -10,56 +39,91 @@ function notFound(res) {
} }
const server = http.createServer((req, res) => { const server = http.createServer((req, res) => {
switch (req.method) { //getAuthorizationState
case 'GET': { myNumber = myNumber+1;
switch (req.url) { console.log(' ')
case '/home': { console.log(' ')
res.statusCode = 200 console.log('---=======- [ '+myNumber+' ] ---------')
res.setHeader('Content-Type', 'text/plain') console.log('This is the METHOD:' + req.method)
res.end('Home page\n') console.log('This is the URL:' + req.url)
break console.log('This is the REQUEST Hdrs:')
}
case '/about': { console.log(req.headers)
res.statusCode = 200
res.setHeader('Content-Type', 'text/plain') switch (req.method) {
res.end('About page\n') case 'GET': {
break switch (req.url) {
} case '/home': {
default: { res.statusCode = 200
notFound(res) res.setHeader('Content-Type', 'text/plain')
break res.end('Home page\n')
} break
} }
case '/about': {
break res.statusCode = 200
} res.setHeader('Content-Type', 'text/plain')
case 'POST': { res.end('About page\n')
switch (req.url) { break
case '/api/admin': { }
res.statusCode = 200 case '/test': {
res.setHeader('Content-Type', 'text/plain')
res.end('Create admin request\n') tgclient.invoke({
break _: 'sendMessage',
} chat_id: 124987160,
case '/api/user': { input_message_content: {
res.statusCode = 200 _: 'inputMessageText',
res.setHeader('Content-Type', 'text/plain') text: {
res.end('Create user request\n') _: 'formattedText',
break text: '👻 Test 123'
} }
default: { }
notFound(res) })
break
} res.statusCode = 200
} res.setHeader('Content-Type', 'text/plain')
res.end('About page\n')
break
}
case '/': {
res.statusCode = 200
res.setHeader('Content-Type', 'text/plain')
res.end('Hello main\n')
break
}
default: {
notFound(res)
break
}
}
break
}
case 'POST': {
switch (req.url) {
case '/api/admin': {
res.statusCode = 200
res.setHeader('Content-Type', 'text/plain')
res.end('Create admin request\n')
break
}
case '/api/user': {
res.statusCode = 200
res.setHeader('Content-Type', 'text/plain')
res.end('Create user request\n')
break
}
default: {
notFound(res)
break
}
}
break break
} }
default: { default: {
notFound(res) notFound(res)
break break
} }
} }
}) })
server.listen(port, host, () => { server.listen(port, host, () => {
......
const winston = require('winston')
const options = {
file: {
level: 'info',
filename: './logs/app.log',
handleExceptions: true,
json: true,
maxsize: 50242880, // 5MB
maxFiles: 5,
colorize: true,
},
console: {
level: 'debug',
handleExceptions: true,
json: false,
colorize: true,
},
};
const logger = winston.createLogger({
levels: winston.config.npm.levels,
transports: [
new winston.transports.File(options.file),
new winston.transports.Console(options.console)
],
exitOnError: false
})
module.exports = logger
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -20,7 +20,13 @@ ...@@ -20,7 +20,13 @@
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"express": "^4.18.1", "express": "^4.18.1",
"http": "^0.0.1-security" "http": "^0.0.1-security",
"morgan": "^1.10.0",
"morgan-json": "^1.1.0",
"pm2": "^5.2.0",
"tdl": "^7.1.0",
"tdl-tdlib-addon": "^1.2.1",
"winston": "^2.4.6"
}, },
"devDependencies": { "devDependencies": {
"logger-service": "^1.0.2" "logger-service": "^1.0.2"
......
const { Client } = require('tdl')
const { TDLib } = require('tdl-tdlib-addon')
var path = require('path');
const tgclient = new Client(new TDLib(path.join(__dirname, 'td/build/libtdjson.so')), {
apiId: 234569,
apiHash: 'ee77bf549e61d3de158916126c8ef7dd'
})
tgclient.on('error', console.error)
tgclient.on('update', update => {
console.log('Received update:', update)
})
async function main () {
await tgclient.connectAndLogin()
console.log(await tgclient.invoke({ _: 'getMe' }))
// ...
}
main().catch(console.error)
module.exports = tgclient
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment