2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +00:00
books/server/index.js
2018-01-23 17:56:40 +05:30

49 lines
1.3 KiB
JavaScript

const backends = {};
backends.sqlite = require('frappejs/backends/sqlite');
const express = require('express');
const app = express();
const frappe = require('frappejs');
const rest_api = require('./rest_api')
const models = require('frappejs/server/models');
const common = require('frappejs/common');
const bodyParser = require('body-parser');
const path = require('path');
module.exports = {
async start({backend, connection_params, static, models_path}) {
await this.init();
models.init_models(path.resolve('node_modules', 'frappejs', 'models'));
models.init_models(models_path);
await this.init_db({backend:backend, connection_params:connection_params});
// database
// app
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static('./'));
// routes
rest_api.setup(app);
// listen
frappe.app = app;
frappe.server = app.listen(frappe.config.port);
},
async init() {
await frappe.init();
common.init_libs(frappe);
await frappe.login();
},
async init_db({backend, connection_params}) {
frappe.db = await new backends[backend].Database(connection_params);
await frappe.db.connect();
await frappe.db.migrate();
},
}