mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 14:17:22 +01:00
for the upcoming api v3 Reorganize files under /src, separate express app in two apps, one for api v1 and v2 and the other for the upcoming api v3 move api v2 routes in a separate folder, rename apiv1 file for better readability, remove auth routes for api v1 move api-v2 controllers in subdirectory move unorganized files to /libs fix gulp requires and separate server in old (api v1 and v2) and new (api v3) app fix require paths fix require paths fix require paths put api v1 back Reorganize files under /src and separate express app in one for api v1 and v2 and the other for v3
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
import 'coffee-script';
|
|
|
|
import mongoose from 'mongoose';
|
|
import autoinc from 'mongoose-id-autoinc';
|
|
import logging from '../website/src/libs/logging';
|
|
import nconf from 'nconf';
|
|
import utils from '../website/src/libs/utils';
|
|
import repl from 'repl';
|
|
import gulp from 'gulp';
|
|
|
|
// Add additional properties to the repl's context
|
|
let improveRepl = (context) => {
|
|
|
|
// Let "exit" and "quit" terminate the console
|
|
['exit', 'quit'].forEach((term) => {
|
|
Object.defineProperty(context, term, { get() { process.exit(); }});
|
|
});
|
|
|
|
// "clear" clears the screen
|
|
Object.defineProperty(context, 'clear', { get() {
|
|
process.stdout.write('\u001B[2J\u001B[0;0f');
|
|
}});
|
|
|
|
utils.setupConfig();
|
|
|
|
context.Challenge = require('../website/src/models/challenge').model;
|
|
context.Group = require('../website/src/models/group').model;
|
|
context.User = require('../website/src/models/user').model;
|
|
|
|
var isProd = nconf.get('NODE_ENV') === 'production';
|
|
var mongooseOptions = !isProd ? {} : {
|
|
replset: { socketOptions: { keepAlive: 1, connectTimeoutMS: 30000 } },
|
|
server: { socketOptions: { keepAlive: 1, connectTimeoutMS: 30000 } }
|
|
};
|
|
autoinc.init(
|
|
mongoose.connect(
|
|
nconf.get('NODE_DB_URI'),
|
|
mongooseOptions,
|
|
function(err) {
|
|
if (err) throw err;
|
|
logging.info('Connected with Mongoose');
|
|
}
|
|
)
|
|
);
|
|
|
|
};
|
|
|
|
gulp.task('console', (cb) => {
|
|
improveRepl(repl.start({
|
|
prompt: 'Habitica > '
|
|
}).context);
|
|
});
|