forked from actualbudget/actual-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
65 lines (52 loc) · 1.65 KB
/
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
60
61
62
63
64
65
const fs = require('fs');
const express = require('express');
const actuator = require('express-actuator');
const bodyParser = require('body-parser');
const cors = require('cors');
const config = require('./load-config');
const accountApp = require('./app-account');
const syncApp = require('./app-sync');
const app = express();
process.on('unhandledRejection', reason => {
console.log('Rejection:', reason);
});
app.use(cors());
app.use(bodyParser.json({ limit: '20mb' }));
app.use(bodyParser.raw({ type: 'application/actual-sync', limit: '20mb' }));
app.use(bodyParser.raw({ type: 'application/encrypted-file', limit: '50mb' }));
app.use('/sync', syncApp.handlers);
app.use('/account', accountApp.handlers);
app.get('/mode', (req, res) => {
res.send(config.mode);
});
app.use(actuator()); // Provides /health, /metrics, /info
// The web frontend
app.use((req, res, next) => {
res.set('Cross-Origin-Opener-Policy', 'same-origin');
res.set('Cross-Origin-Embedder-Policy', 'require-corp');
next();
});
app.use(
express.static(__dirname + '/node_modules/@actual-app/web/build', {
index: false
})
);
app.get('/*', (req, res) => {
res.sendFile(__dirname + '/node_modules/@actual-app/web/build/index.html');
});
async function run() {
if (!fs.existsSync(config.serverFiles)) {
fs.mkdirSync(config.serverFiles);
}
if (!fs.existsSync(config.userFiles)) {
fs.mkdirSync(config.userFiles);
}
await accountApp.init();
await syncApp.init();
console.log('Listening on ' + config.hostname + ':' + config.port + '...');
app.listen(config.port, config.hostname);
}
run().catch(err => {
console.log('Error starting app:', err);
process.exit(1);
});