mirror of
https://github.com/nioc/xmpp-bot.git
synced 2024-12-04 22:23:36 +01:00
Structure app by self-contained components
This commit is contained in:
parent
100d6bf643
commit
d1da553ec2
13 changed files with 12 additions and 12 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,5 +1,5 @@
|
||||||
/node_modules/
|
/node_modules/
|
||||||
/config.json
|
/lib/config/config.json
|
||||||
/*.log
|
/*.log
|
||||||
/.nyc_output/
|
/.nyc_output/
|
||||||
/coverage/
|
/coverage/
|
||||||
|
|
|
@ -40,10 +40,10 @@ User ⇄ XMPP client ⇄ XMPP Server ⇄ **XMPP Bot** ⇄ REST A
|
||||||
- Create run user (optionnal):
|
- Create run user (optionnal):
|
||||||
```
|
```
|
||||||
useradd -r -s /bin/false xmpp-bot
|
useradd -r -s /bin/false xmpp-bot
|
||||||
chown xmpp-bot:xmpp-bot /usr/local/bin/xmpp-bot -R
|
chown xmpp-bot:xmpp-bot /usr/local/bin/xmpp-bot/lib -R
|
||||||
```
|
```
|
||||||
|
|
||||||
- Set [configuration](#configuration) in `config.json` (you can copy `config.json.dist`)
|
- Set [configuration](#configuration) in `/lib/config/config.json` (you can copy `config.json.dist`)
|
||||||
|
|
||||||
- Add systemd service from [model](/docs/xmpp-bot.service):
|
- Add systemd service from [model](/docs/xmpp-bot.service):
|
||||||
```shell
|
```shell
|
||||||
|
|
|
@ -5,8 +5,8 @@ After=network.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
User=xmpp-bot
|
User=xmpp-bot
|
||||||
WorkingDirectory=/usr/local/bin/xmpp-bot/
|
WorkingDirectory=/usr/local/bin/xmpp-bot/lib/
|
||||||
ExecStart=/usr/bin/node /usr/local/bin/xmpp-bot/server.js
|
ExecStart=/usr/bin/node /usr/local/bin/xmpp-bot/lib/server.js
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
RestartSec=1000ms
|
RestartSec=1000ms
|
||||||
Environment=NODE_ENV=production
|
Environment=NODE_ENV=production
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
module.exports = function Configuration (logger) {
|
module.exports = function Configuration (logger) {
|
||||||
let config
|
let config
|
||||||
try {
|
try {
|
||||||
let data = require('fs').readFileSync('./config.json')
|
let data = require('fs').readFileSync('./lib/config/config.json')
|
||||||
config = JSON.parse(data)
|
config = JSON.parse(data)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.fatal(`Invalid configuration file: ${error.message}`)
|
logger.fatal(`Invalid configuration file: ${error.message}`)
|
|
@ -38,7 +38,7 @@ module.exports = (logger, config) => {
|
||||||
switch (xmppHook.action) {
|
switch (xmppHook.action) {
|
||||||
case 'outgoing_webhook':
|
case 'outgoing_webhook':
|
||||||
logger.debug(`Call outgoing webhook: ${xmppHook.args[0]}`)
|
logger.debug(`Call outgoing webhook: ${xmppHook.args[0]}`)
|
||||||
require('./outgoing')(logger, config, xmpp, from, from, message, false, xmppHook.args[0])
|
require('../outgoing')(logger, config, xmpp, from, from, message, false, xmppHook.args[0])
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
|
@ -62,7 +62,7 @@ module.exports = (logger, config) => {
|
||||||
switch (xmppHook.action) {
|
switch (xmppHook.action) {
|
||||||
case 'outgoing_webhook':
|
case 'outgoing_webhook':
|
||||||
logger.debug(`Call outgoing webhook: ${xmppHook.args[0]}`)
|
logger.debug(`Call outgoing webhook: ${xmppHook.args[0]}`)
|
||||||
require('./outgoing')(logger, config, xmpp, from, conference, message, true, xmppHook.args[0])
|
require('../outgoing')(logger, config, xmpp, from, conference, message, true, xmppHook.args[0])
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
|
@ -2,10 +2,10 @@
|
||||||
"name": "xmpp-bot",
|
"name": "xmpp-bot",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "XMPP bot",
|
"description": "XMPP bot",
|
||||||
"main": "server.js",
|
"main": "./lib/server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "nodemon server.js",
|
"dev": "nodemon lib/server.js",
|
||||||
"start": "NODE_ENV=production node server.js",
|
"start": "NODE_ENV=production node lib/server.js",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"test": "mocha",
|
"test": "mocha",
|
||||||
"cover": "nyc --reporter=html --reporter=text mocha"
|
"cover": "nyc --reporter=html --reporter=text mocha"
|
||||||
|
|
|
@ -4,7 +4,7 @@ process.env.NODE_ENV = 'production'
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
const should = require('chai').should()
|
const should = require('chai').should()
|
||||||
let request = require('request')
|
let request = require('request')
|
||||||
let server = require('../server')
|
let server = require('../lib/server')
|
||||||
const baseUrl = 'http://localhost:8000/'
|
const baseUrl = 'http://localhost:8000/'
|
||||||
|
|
||||||
after((done) => {
|
after((done) => {
|
||||||
|
|
Loading…
Reference in a new issue