mirror of
https://github.com/frappe/books.git
synced 2024-11-10 15:50:56 +00:00
32cd6581d1
- /api/method/pdf - frappe.getPDF - download using blob url
69 lines
1.9 KiB
JavaScript
69 lines
1.9 KiB
JavaScript
const backends = {};
|
|
backends.sqlite = require('frappejs/backends/sqlite');
|
|
//backends.mysql = require('frappejs/backends/mysql');
|
|
|
|
const express = require('express');
|
|
const app = express();
|
|
const server = require('http').Server(app);
|
|
const io = require('socket.io')(server);
|
|
const frappe = require('frappejs');
|
|
const restAPI = require('./restAPI');
|
|
const frappeModels = require('frappejs/models');
|
|
const common = require('frappejs/common');
|
|
const bodyParser = require('body-parser');
|
|
const fs = require('fs');
|
|
const { setupExpressRoute: setRouteForPDF } = require('frappejs/server/pdf');
|
|
|
|
require.extensions['.html'] = function (module, filename) {
|
|
module.exports = fs.readFileSync(filename, 'utf8');
|
|
};
|
|
|
|
module.exports = {
|
|
async start({backend, connectionParams, models, staticPath = './'}) {
|
|
|
|
await this.init();
|
|
|
|
if (models) {
|
|
frappe.registerModels(models, 'server');
|
|
}
|
|
|
|
// database
|
|
await this.initDb({backend:backend, connectionParams:connectionParams});
|
|
|
|
// app
|
|
app.use(bodyParser.json());
|
|
app.use(bodyParser.urlencoded({ extended: true }));
|
|
app.use(express.static(staticPath));
|
|
|
|
// socketio
|
|
io.on('connection', function (socket) {
|
|
frappe.db.bindSocketServer(socket);
|
|
});
|
|
// routes
|
|
restAPI.setup(app);
|
|
|
|
// listen
|
|
server.listen(frappe.config.port);
|
|
|
|
frappe.app = app;
|
|
frappe.server = server;
|
|
|
|
setRouteForPDF();
|
|
},
|
|
|
|
async init() {
|
|
frappe.isServer = true;
|
|
await frappe.init();
|
|
frappe.registerModels(frappeModels, 'server');
|
|
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();
|
|
},
|
|
}
|