-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce1bd7a
commit de214f6
Showing
3 changed files
with
60 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,35 @@ | ||
var express = require('express'); | ||
var app = express(); | ||
const express = require('express'), | ||
PropertiesReader = require('properties-reader'); | ||
const app = express(); | ||
|
||
//Globals | ||
|
||
global._base = __dirname + '/'; | ||
global._db = PropertiesReader(_base + 'resources/db.properties'); | ||
global._env = app.get('env'); | ||
global._isDev = _env === 'development'; | ||
global._isProd = _env === 'production'; | ||
|
||
console.info = function(message) { | ||
console.log('[INFO] ' + message); | ||
} | ||
|
||
console.debug = function(message) { | ||
console.log('[DEBUG] ' + message); | ||
} | ||
|
||
console.critical = function(message) { | ||
console.log('[!!! CRITICAL !!!] ' + message); | ||
} | ||
|
||
const setUpDatabase = require(_base + 'services/SetupDatabaseService'); | ||
setUpDatabase(); | ||
|
||
|
||
app.get('/api', (req, res) => { | ||
res.json({message: 'Welcome to the Server'}); | ||
res.json({message: 'Welcome to the Server'}); | ||
}); | ||
app.listen(8880, ()=>{ | ||
console.log('API listening on port 8081'); | ||
|
||
app.listen(8081, ()=>{ | ||
console.log('API listening on port 8081'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
db.connection.development=mongodb://127.0.0.1:27017/image-board | ||
|
||
db.collection.categories=categories | ||
db.collection.boards=boards | ||
db.collection.threads=threads | ||
db.collection.replies=replies | ||
db.collection.mods=mods | ||
db.collection.bans=bans |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
let mongoose = require('mongoose'); | ||
|
||
module.exports = function() { | ||
let url = _db.get('db.connection.' + _env); | ||
console.info('Attempting to connect to ' + url); | ||
mongoose.connect(url); | ||
mongoose.connection.on('connected', function() { | ||
console.info('Database connection established'); | ||
}); | ||
|
||
mongoose.connection.on('error', function(err) { | ||
console.critical('Cannot connect to database'); | ||
console.critical(JSON.stringify(err)); | ||
return process.exit(); | ||
}); | ||
|
||
mongoose.connection.on('disconnected', function() { | ||
console.info('Database disconnected'); | ||
}); | ||
} |