diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index f4ca8ad..0000000 --- a/.dockerignore +++ /dev/null @@ -1,10 +0,0 @@ -node_modules -.next -.git -.env.local -npm-debug.log* -yarn-debug.log* -yarn-error.log* -.DS_Store -dist -coverage diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 788f647..0000000 --- a/Dockerfile +++ /dev/null @@ -1,22 +0,0 @@ -FROM node:20-alpine AS runner -WORKDIR /app - -ENV NODE_ENV production -ENV PORT 3000 - -# Install OpenSSL for compatibility -RUN apk add --no-cache openssl - -# Copy necessary files -# Standalone build already includes node_modules -COPY .next/standalone ./ -COPY .next/static ./.next/static -COPY public ./public - -# Copy prisma for database migrations -COPY prisma ./prisma - -EXPOSE 3000 - -# Run migrations and then start the server -CMD ["sh", "-c", "npx prisma db push && node server.js"] diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 5860c3c..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,15 +0,0 @@ -version: '3' -services: - noteai: - image: noteai - build: . - container_name: noteai - restart: always - ports: - - "4500:3000" - volumes: - # Persist the database file - - ./prisma/dev.db:/app/prisma/dev.db - environment: - - DATABASE_URL=file:./prisma/dev.db - - TZ=Asia/Shanghai diff --git a/next.config.ts b/next.config.ts index 4d3e18a..a20b951 100644 --- a/next.config.ts +++ b/next.config.ts @@ -2,7 +2,6 @@ import type { NextConfig } from "next"; import packageJson from "./package.json"; const nextConfig: NextConfig = { - output: "standalone", env: { NEXT_PUBLIC_APP_VERSION: packageJson.version, }, diff --git a/package.json b/package.json index f83ff16..e37f8cd 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,9 @@ "scripts": { "dev": "next dev -p 3001", "build": "next build", - "start": "next start", + "env:init": "node scripts/init-env.mjs", + "build:init": "npm run env:init && npm run build", + "start": "next start -p 3001", "lint": "eslint", "test": "node --no-warnings --experimental-strip-types scripts/run-editor-block-ops-tests.mjs", "check": "npm run lint -- --max-warnings=0 && npx tsc --noEmit" diff --git a/prisma/dev.db b/prisma/dev.db index 05f5999..1cbb1bb 100644 Binary files a/prisma/dev.db and b/prisma/dev.db differ diff --git a/scripts/init-env.mjs b/scripts/init-env.mjs new file mode 100644 index 0000000..6659896 --- /dev/null +++ b/scripts/init-env.mjs @@ -0,0 +1,57 @@ +import { randomBytes } from "node:crypto"; +import { existsSync, readFileSync, writeFileSync } from "node:fs"; +import { resolve } from "node:path"; + +const envPath = resolve(process.cwd(), ".env"); +const envExists = existsSync(envPath); +const original = envExists ? readFileSync(envPath, "utf8") : ""; +const lines = original ? original.split(/\r?\n/) : []; + +const parsed = new Map(); +for (const line of lines) { + const trimmed = line.trim(); + if (!trimmed || trimmed.startsWith("#")) continue; + const match = trimmed.match(/^([A-Z0-9_]+)\s*=\s*(.*)$/); + if (!match) continue; + parsed.set(match[1], match[2]); +} + +const required = [ + { + key: "DATABASE_URL", + value: '"file:./dev.db"', + }, + { + key: "SESSION_SECRET", + value: `"${randomBytes(32).toString("hex")}"`, + }, + { + key: "INIT_SETUP_TOKEN", + value: `"${randomBytes(24).toString("hex")}"`, + }, + { + key: "INIT_DEFAULT_PASSWORD", + value: `"${randomBytes(9).toString("base64url")}"`, + }, +]; + +const added = []; +for (const item of required) { + if (!parsed.has(item.key)) { + lines.push(`${item.key}=${item.value}`); + added.push(item.key); + } +} + +if (!envExists && lines.length === 0) { + lines.push("# Generated by scripts/init-env.mjs"); +} + +const next = `${lines.filter((line, index, arr) => !(line === "" && index === arr.length - 1)).join("\n")}\n`; +writeFileSync(envPath, next, "utf8"); + +if (added.length === 0) { + console.log("init-env: no missing keys, .env unchanged"); +} else { + console.log(`init-env: added ${added.join(", ")}`); +}