mirror of
https://github.com/frappe/books.git
synced 2024-11-10 15:50:56 +00:00
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
const backends = {};
|
|
backends.sqlite = require('frappejs/backends/sqlite');
|
|
//backends.mysql = require('frappejs/backends/mysql');
|
|
|
|
const express = require('express');
|
|
const app = express();
|
|
const frappe = require('frappejs');
|
|
const rest_api = require('./rest_api');
|
|
const frappeModels = require('frappejs/models');
|
|
const common = require('frappejs/common');
|
|
const bodyParser = require('body-parser');
|
|
|
|
module.exports = {
|
|
async start({backend, connectionParams, models}) {
|
|
await this.init();
|
|
|
|
if (models) {
|
|
frappe.registerModels(models);
|
|
}
|
|
|
|
// database
|
|
await this.initDb({backend:backend, connectionParams:connectionParams});
|
|
|
|
// 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();
|
|
frappe.registerModels(frappeModels);
|
|
frappe.registerLibs(common);
|
|
await frappe.login();
|
|
},
|
|
|
|
async initDb({backend, connectionParams}) {
|
|
frappe.db = await new backends[backend](connectionParams);
|
|
await frappe.db.connect();
|
|
await frappe.db.migrate();
|
|
},
|
|
}
|