clean configuration

This commit is contained in:
lesion
2019-04-30 15:16:50 +02:00
parent e50e5434bc
commit 69792b518e
14 changed files with 121 additions and 84 deletions

View File

@@ -1,5 +1,5 @@
const { Op } = require('sequelize')
const config = require('./config')
const config = require('../../config')
const User = require('./models/user')
const Auth = {

View File

@@ -1,27 +0,0 @@
/* backend configuration */
const env = process.env.NODE_ENV || 'development'
const db = require('./config/config.json')[env]
module.exports = {
locale: process.env.LOCALE || 'it',
title: process.env.TITLE || 'GANCIO',
description: process.env.DESCRIPTION || 'A calendar for radical communities',
baseurl: process.env.BASE_URL || 'http://localhost:3000',
apiurl:
env === 'production'
? process.env.BASE_URL + '/api'
: 'http://localhost:3000/api',
db,
admin: process.env.ADMIN_EMAIL,
smtp: {
host: process.env.SMTP_HOST,
secure: true,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS
}
},
secret: process.env.SECRET || 'notsosecret'
}

View File

@@ -1,5 +1,5 @@
const { User, Event, Comment, Tag } = require('../model')
const config = require('../config')
const config = require('../../../config')
const Mastodon = require('mastodon-api')
// const Sequelize = require('sequelize')
// const Op = Sequelize.Op
@@ -12,11 +12,9 @@ moment.locale('it')
const botController = {
bot: null,
async initialize () {
console.log('initialize bot')
const settings = await settingsController.settings()
if (!settings.mastodon_auth) return
const mastodon_auth = settings.mastodon_auth
console.log('instance ', `https://${mastodon_auth.instance}/api/v1/`)
botController.bot = new Mastodon({
access_token: mastodon_auth.access_token,
api_url: `https://${mastodon_auth.instance}/api/v1`
@@ -45,7 +43,6 @@ const botController = {
// botController.bots.push({ email: user.email, bot })
},
async post (mastodon_auth, event) {
console.log('dentro post!')
const { access_token, instance } = mastodon_auth
const bot = new Mastodon({ access_token, api_url: `https://${instance}/api/v1/` })
const status = `${event.title} @ ${event.place.name} ${moment(event.start_datetime).format('ddd, D MMMM HH:mm')} -
@@ -67,7 +64,6 @@ ${event.description.length > 200 ? event.description.substr(0, 200) + '...' : ev
if (!replyid) return
const event = await Event.findOne({ where: { activitypub_id: replyid } })
if (!event) {
console.error('associated event not found !')
// check for comment..
// const comment = await Comment.findOne( {where: { }})
return
@@ -79,7 +75,6 @@ ${event.description.length > 200 ? event.description.substr(0, 200) + '...' : ev
author: msg.data.accounts[0].username
})
event.addComment(comment)
console.log(event)
// const comment = await Comment.findOne( { where: {activitypub_id: msg.data.in_reply_to}} )
// console.log('dentro message ', data)

View File

@@ -1,6 +1,6 @@
const { Event, Comment, Tag, Place } = require('../model')
const { Op } = require('sequelize')
const config = require('../config')
const config = require('../../../config')
const moment = require('moment')
const ics = require('ics')

View File

@@ -6,7 +6,7 @@ const Mastodon = require('mastodon-api')
const { Op } = require('sequelize')
const jsonwebtoken = require('jsonwebtoken')
const User = require('../models/user')
const config = require('../config')
const config = require('../../../config')
const mail = require('../mail')
const { Event, Tag, Place } = require('../models/event')
const settingsController = require('./settings')

View File

@@ -1,5 +1,5 @@
const Sequelize = require('sequelize')
const conf = require('./config.js')
const conf = require('../../config.js')
const db = new Sequelize(conf.db)
db.sync()
module.exports = db

View File

@@ -5,7 +5,7 @@ const eventController = require('./controller/event')
const exportController = require('./controller/export')
const userController = require('./controller/user')
const settingsController = require('./controller/settings')
const config = require('./config')
const config = require('../../config')
const botController = require('./controller/bot')
const jwt = require('express-jwt')({secret: config.secret})

View File

@@ -1,8 +1,8 @@
const Email = require('email-templates')
const path = require('path')
const config = require('./config')
const config = require('../../config')
const moment = require('moment')
moment.locale('it')
moment.locale(config.locale)
const mail = {
send (addresses, template, locals) {

View File

@@ -1,37 +1,29 @@
'use strict';
const fs = require('fs')
const path = require('path')
const Sequelize = require('sequelize')
const basename = path.basename(__filename)
const config = require('../../../config')
const db = {}
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../config/config.json')[env];
const db = {};
let sequelize;
if (config.use_env_variable) {
sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
sequelize = new Sequelize(config.database, config.username, config.password, config);
}
const sequelize = new Sequelize(config.db)
fs
.readdirSync(__dirname)
.filter(file => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js')
})
.forEach(file => {
const model = sequelize['import'](path.join(__dirname, file));
const model = sequelize['import'](path.join(__dirname, file))
db[model.name] = model;
});
Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
db[modelName].associate(db)
}
});
})
db.sequelize = sequelize;
db.Sequelize = Sequelize;
db.sequelize = sequelize
db.Sequelize = Sequelize
module.exports = db;