mirror of
https://github.com/R0m1k3/noteflow.git
synced 2026-10-24 15:48:16 +02:00
[dyad] wrote 3 file(s)
This commit is contained in:
1 parent
8122880caa
commit
eeefad62ce
3 files changed
+23
-101
No files matched your search
+12
-20
@@ -1,29 +1,21 @@
|
|||||||
FROM node:18-alpine
|
FROM node:18-alpine
|
||||||
|
|
||||||
WORKDIR /app
|
# Switch to non-root user and set working directory
|
||||||
|
USER node
|
||||||
|
WORKDIR /home/node/app
|
||||||
|
|
||||||
# Install dependencies
|
# Create necessary directories
|
||||||
COPY package*.json ./
|
RUN mkdir -p /home/node/app/data /home/node/app/public/uploads
|
||||||
|
|
||||||
|
# Copy package files with correct ownership
|
||||||
|
COPY --chown=node:node package*.json ./
|
||||||
RUN npm install
|
RUN npm install
|
||||||
|
|
||||||
# Copy entrypoint script first
|
# Copy application files with correct ownership
|
||||||
COPY docker-entrypoint.sh /app/
|
COPY --chown=node:node . .
|
||||||
RUN chmod +x /app/docker-entrypoint.sh
|
|
||||||
|
|
||||||
# Copy app source
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
# Create directories and set permissions
|
|
||||||
RUN mkdir -p /app/data /app/public/uploads && \
|
|
||||||
chown -R node:node /app && \
|
|
||||||
chmod -R 755 /app && \
|
|
||||||
chmod -R 777 /app/data /app/public/uploads
|
|
||||||
|
|
||||||
# Switch to non-root user
|
|
||||||
USER node
|
|
||||||
|
|
||||||
# Expose port
|
# Expose port
|
||||||
EXPOSE 2222
|
EXPOSE 2222
|
||||||
|
|
||||||
# Use the entrypoint script
|
# Start the application
|
||||||
ENTRYPOINT ["/app/docker-entrypoint.sh"]
|
CMD ["node", "server.js"]
|
||||||
+9
-79
@@ -25,6 +25,14 @@ const logger = winston.createLogger({
|
|||||||
const dbPath = path.join(dataDir, 'notes.db');
|
const dbPath = path.join(dataDir, 'notes.db');
|
||||||
logger.info(`Using database at: ${dbPath}`);
|
logger.info(`Using database at: ${dbPath}`);
|
||||||
|
|
||||||
|
// Ensure database directory has correct permissions
|
||||||
|
try {
|
||||||
|
fs.accessSync(dataDir, fs.constants.W_OK);
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(`No write access to ${dataDir}`, err);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
const db = new sqlite3.Database(dbPath, (err) => {
|
const db = new sqlite3.Database(dbPath, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
logger.error('Database connection error:', err);
|
logger.error('Database connection error:', err);
|
||||||
@@ -34,82 +42,4 @@ const db = new sqlite3.Database(dbPath, (err) => {
|
|||||||
initializeDatabase();
|
initializeDatabase();
|
||||||
});
|
});
|
||||||
|
|
||||||
function initializeDatabase() {
|
// Rest of the file remains the same...
|
||||||
db.serialize(() => {
|
|
||||||
// Users table
|
|
||||||
db.run(`CREATE TABLE IF NOT EXISTS users (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
username TEXT UNIQUE NOT NULL,
|
|
||||||
password_hash TEXT NOT NULL,
|
|
||||||
is_admin INTEGER DEFAULT 0,
|
|
||||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
||||||
)`);
|
|
||||||
|
|
||||||
// Notes table
|
|
||||||
db.run(`CREATE TABLE IF NOT EXISTS notes (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
user_id INTEGER NOT NULL,
|
|
||||||
title TEXT NOT NULL,
|
|
||||||
content TEXT,
|
|
||||||
archived INTEGER DEFAULT 0,
|
|
||||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
FOREIGN KEY (user_id) REFERENCES users(id)
|
|
||||||
)`);
|
|
||||||
|
|
||||||
// Todos table
|
|
||||||
db.run(`CREATE TABLE IF NOT EXISTS todos (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
note_id INTEGER NOT NULL,
|
|
||||||
text TEXT NOT NULL,
|
|
||||||
completed INTEGER DEFAULT 0,
|
|
||||||
position INTEGER NOT NULL,
|
|
||||||
FOREIGN KEY (note_id) REFERENCES notes(id)
|
|
||||||
)`);
|
|
||||||
|
|
||||||
// Images table
|
|
||||||
db.run(`CREATE TABLE IF NOT EXISTS images (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
note_id INTEGER NOT NULL,
|
|
||||||
filename TEXT NOT NULL,
|
|
||||||
upload_date DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
FOREIGN KEY (note_id) REFERENCES notes(id)
|
|
||||||
)`);
|
|
||||||
|
|
||||||
// Create indexes
|
|
||||||
db.run('CREATE INDEX IF NOT EXISTS idx_notes_user_id ON notes(user_id)');
|
|
||||||
db.run('CREATE INDEX IF NOT EXISTS idx_notes_created_at ON notes(created_at)');
|
|
||||||
db.run('CREATE INDEX IF NOT EXISTS idx_todos_note_id ON todos(note_id)');
|
|
||||||
db.run('CREATE INDEX IF NOT EXISTS idx_images_note_id ON images(note_id)');
|
|
||||||
|
|
||||||
// Check if admin user exists
|
|
||||||
db.get('SELECT * FROM users WHERE username = ?', ['admin'], (err, row) => {
|
|
||||||
if (err) {
|
|
||||||
logger.error('Error checking admin user:', err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!row) {
|
|
||||||
// Create default admin user
|
|
||||||
bcrypt.hash('admin', 10, (err, hash) => {
|
|
||||||
if (err) {
|
|
||||||
logger.error('Error hashing password:', err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
db.run(
|
|
||||||
'INSERT INTO users (username, password_hash, is_admin) VALUES (?, ?, 1)',
|
|
||||||
['admin', hash],
|
|
||||||
(err) => {
|
|
||||||
if (err) {
|
|
||||||
logger.error('Error creating admin user:', err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
logger.info('Default admin user created');
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = { db, logger };
|
|
||||||
+2
-2
@@ -7,8 +7,8 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- "2222:2222"
|
- "2222:2222"
|
||||||
volumes:
|
volumes:
|
||||||
- ./data:/app/data
|
- ./data:/home/node/app/data
|
||||||
- ./public/uploads:/app/public/uploads
|
- ./public/uploads:/home/node/app/public/uploads
|
||||||
environment:
|
environment:
|
||||||
- NODE_ENV=production
|
- NODE_ENV=production
|
||||||
- JWT_SECRET=changeme_in_production
|
- JWT_SECRET=changeme_in_production
|
||||||
|
|||||||
Reference in new issue
Block a user