Improve how data dirs are treated

This commit is contained in:
James Long 2022-04-29 11:10:20 -04:00
parent b53a4e5bf8
commit cd280802de
5 changed files with 19 additions and 2 deletions

View file

@ -7,6 +7,9 @@ RUN mkdir /app
WORKDIR /app WORKDIR /app
ENV NODE_ENV=production ENV NODE_ENV=production
ADD . . ADD . .
RUN yarn install --production RUN yarn install --production

View file

@ -6,6 +6,11 @@ let accountDb = null;
function getAccountDb() { function getAccountDb() {
if (accountDb == null) { if (accountDb == null) {
if (!fs.existsSync(config.serverFiles)) {
console.log('MAKING SERVER DIR');
fs.mkdirSync(config.serverFiles);
}
let dbPath = join(config.serverFiles, 'account.sqlite'); let dbPath = join(config.serverFiles, 'account.sqlite');
let needsInit = !fs.existsSync(dbPath); let needsInit = !fs.existsSync(dbPath);

View file

@ -19,7 +19,7 @@ const app = express();
app.use(errorMiddleware); app.use(errorMiddleware);
async function init() { async function init() {
let fileDir = join(__dirname, process.env.ACTUAL_USER_FILES || config.userFiles); let fileDir = join(process.env.ACTUAL_USER_FILES || config.userFiles);
console.log('Initializing Actual with user file dir:', fileDir); console.log('Initializing Actual with user file dir:', fileDir);

9
app.js
View file

@ -1,3 +1,4 @@
const fs = require('fs');
const express = require('express'); const express = require('express');
const bodyParser = require('body-parser'); const bodyParser = require('body-parser');
const cors = require('cors'); const cors = require('cors');
@ -31,6 +32,14 @@ app.get('/*', (req, res) => {
}); });
async function run() { 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 accountApp.init();
await syncApp.init(); await syncApp.init();

View file

@ -4,7 +4,7 @@ try {
} catch (e) { } catch (e) {
let fs = require('fs'); let fs = require('fs');
let { join } = require('path'); let { join } = require('path');
let root = fs.existsSync('/data') ? '/data' : './'; let root = fs.existsSync('/data') ? '/data' : __dirname;
config = { config = {
mode: 'development', mode: 'development',