Commit 4180613f authored by Steven's avatar Steven

fix: update demo mode handling

parent 324f7959
...@@ -191,7 +191,7 @@ cd proto && buf generate ...@@ -191,7 +191,7 @@ cd proto && buf generate
```bash ```bash
# Start dev server # Start dev server
go run ./cmd/memos --mode dev --port 8081 go run ./cmd/memos --port 8081
# Run all tests # Run all tests
go test ./... go test ./...
...@@ -458,7 +458,7 @@ cd web && pnpm lint ...@@ -458,7 +458,7 @@ cd web && pnpm lint
| Variable | Default | Description | | Variable | Default | Description |
|----------|----------|-------------| |----------|----------|-------------|
| `MEMOS_MODE` | `dev` | Mode: `dev`, `prod`, `demo` | | `MEMOS_DEMO` | `false` | Enable demo mode |
| `MEMOS_PORT` | `8081` | HTTP port | | `MEMOS_PORT` | `8081` | HTTP port |
| `MEMOS_ADDR` | `` | Bind address (empty = all) | | `MEMOS_ADDR` | `` | Bind address (empty = all) |
| `MEMOS_DATA` | `~/.memos` | Data directory | | `MEMOS_DATA` | `~/.memos` | Data directory |
...@@ -564,7 +564,7 @@ Each plugin has its own README with usage examples. ...@@ -564,7 +564,7 @@ Each plugin has its own README with usage examples.
## Security Notes ## Security Notes
- JWT secrets must be kept secret (`MEMOS_MODE=prod` generates random secret) - JWT secrets must be kept secret (generated on first run in production mode)
- Personal Access Tokens stored as SHA-256 hashes in database - Personal Access Tokens stored as SHA-256 hashes in database
- CSRF protection via SameSite cookies - CSRF protection via SameSite cookies
- CORS enabled for all origins (configure for production) - CORS enabled for all origins (configure for production)
......
...@@ -57,14 +57,22 @@ func (p *Profile) Validate() error { ...@@ -57,14 +57,22 @@ func (p *Profile) Validate() error {
// Set default data directory if not specified // Set default data directory if not specified
if p.Data == "" { if p.Data == "" {
if p.Demo { if p.Demo {
// In demo mode, use a temporary directory or current directory // In demo mode, use current directory
p.Data = "." p.Data = "."
} else { } else {
// In production mode, use system directory // In production mode, use system directory
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
p.Data = filepath.Join(os.Getenv("ProgramData"), "memos") p.Data = filepath.Join(os.Getenv("ProgramData"), "memos")
} else { } else {
// On Linux/macOS, check if /var/opt/memos exists (Docker scenario)
// If not, fall back to current directory to avoid permission issues
if _, err := os.Stat("/var/opt/memos"); err == nil {
p.Data = "/var/opt/memos" p.Data = "/var/opt/memos"
} else {
slog.Warn("default production data directory /var/opt/memos not accessible, using current directory. " +
"Consider using --data flag to specify a data directory.")
p.Data = "."
}
} }
} }
} }
......
...@@ -47,7 +47,6 @@ USER nonroot:nonroot ...@@ -47,7 +47,6 @@ USER nonroot:nonroot
VOLUME /var/opt/memos VOLUME /var/opt/memos
ENV TZ="UTC" \ ENV TZ="UTC" \
MEMOS_MODE="prod" \
MEMOS_PORT="5230" MEMOS_PORT="5230"
EXPOSE 5230 EXPOSE 5230
......
...@@ -29,4 +29,4 @@ go build -o "$OUTPUT" ./cmd/memos ...@@ -29,4 +29,4 @@ go build -o "$OUTPUT" ./cmd/memos
echo "Build successful!" echo "Build successful!"
echo "To run the application, execute the following command:" echo "To run the application, execute the following command:"
echo "$OUTPUT --mode dev" echo "$OUTPUT"
...@@ -174,10 +174,10 @@ To run with demo data: ...@@ -174,10 +174,10 @@ To run with demo data:
```bash ```bash
# Start in demo mode # Start in demo mode
go run ./cmd/memos --mode demo --port 8081 go run ./cmd/memos --demo --port 8081
# Or use the binary # Or use the binary
./memos --mode demo ./memos --demo
# Demo database location # Demo database location
./build/memos_demo.db ./build/memos_demo.db
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment