Structure app by self-contained components

This commit is contained in:
nioc 2019-10-18 22:42:04 +02:00
parent 100d6bf643
commit d1da553ec2
13 changed files with 12 additions and 12 deletions

2
.gitignore vendored
View file

@ -1,5 +1,5 @@
/node_modules/
/config.json
/lib/config/config.json
/*.log
/.nyc_output/
/coverage/

View file

@ -40,10 +40,10 @@ User ⇄ XMPP client ⇄ XMPP Server ⇄ **XMPP Bot** ⇄ REST A
- Create run user (optionnal):
```
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):
```shell

View file

@ -5,8 +5,8 @@ After=network.target
[Service]
User=xmpp-bot
WorkingDirectory=/usr/local/bin/xmpp-bot/
ExecStart=/usr/bin/node /usr/local/bin/xmpp-bot/server.js
WorkingDirectory=/usr/local/bin/xmpp-bot/lib/
ExecStart=/usr/bin/node /usr/local/bin/xmpp-bot/lib/server.js
Restart=on-failure
RestartSec=1000ms
Environment=NODE_ENV=production

View file

@ -12,7 +12,7 @@
module.exports = function Configuration (logger) {
let config
try {
let data = require('fs').readFileSync('./config.json')
let data = require('fs').readFileSync('./lib/config/config.json')
config = JSON.parse(data)
} catch (error) {
logger.fatal(`Invalid configuration file: ${error.message}`)

View file

@ -38,7 +38,7 @@ module.exports = (logger, config) => {
switch (xmppHook.action) {
case 'outgoing_webhook':
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
default:
break
@ -62,7 +62,7 @@ module.exports = (logger, config) => {
switch (xmppHook.action) {
case 'outgoing_webhook':
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
default:
break

View file

@ -2,10 +2,10 @@
"name": "xmpp-bot",
"version": "1.0.0",
"description": "XMPP bot",
"main": "server.js",
"main": "./lib/server.js",
"scripts": {
"dev": "nodemon server.js",
"start": "NODE_ENV=production node server.js",
"dev": "nodemon lib/server.js",
"start": "NODE_ENV=production node lib/server.js",
"lint": "eslint .",
"test": "mocha",
"cover": "nyc --reporter=html --reporter=text mocha"

View file

@ -4,7 +4,7 @@ process.env.NODE_ENV = 'production'
// eslint-disable-next-line no-unused-vars
const should = require('chai').should()
let request = require('request')
let server = require('../server')
let server = require('../lib/server')
const baseUrl = 'http://localhost:8000/'
after((done) => {