-
Notifications
You must be signed in to change notification settings - Fork 1
/
crudbase-app.js
59 lines (42 loc) · 1.67 KB
/
crudbase-app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"use strict";
const CrudbaseApp = function (options){
this.options = options;
this.options.port = this.options.port || 6100;
this.options.env = this.options.env || process.env.NODE_ENV;
this.options.modelNameArray = this.options.modelNameArray || null;
this.app = {};
this.db = 'still nothing';
this.routes = 'still nothing';
// console.log(this.options);
// console.log(this.db);
const express = require('express');
const colors = require('colors');
this.app = express();
const bodyParser = require('body-parser');
this.app.use(bodyParser.json());
const logger = function(req, res, next) {
console.log(colors.blue(new Date().toLocaleString()) + " : " + colors.green(req.method) + " : " + req.url);
next();
};
this.app.use(logger);
const entityLoader = require('./lib/entity-loader');
this.db = entityLoader(this.options.modelNameArray);
const createRoutes = require('./lib/schema-to-routes');
this.routes = createRoutes(this.db);
this.app.use(this.routes);
this.app.use(express.static('public'));
this.app.use('/angular', express.static(__dirname + '/node_modules/angular/'));
this.app.use('/bootstrap', express.static(__dirname + '/node_modules/bootstrap/dist/css/'));
this.app.use('/node_modules/ng-admin/build/', express.static(__dirname + '/node_modules/ng-admin/build/'));
this.app.listen(options.port, function () {
console.log(
colors.red(new Date().toLocaleString()) + " : " +
colors.cyan('Environment: ' + options.env) + " : " +
colors.cyan('Running on port: ' + options.port)
);
});
};
CrudbaseApp.prototype.stop = () => {
this.app.stop();
};
module.exports = CrudbaseApp;