fix: update demo mode handling

This commit is contained in:
Steven 2026-01-21 07:36:30 +08:00
parent 324f795965
commit 4180613fc0
5 changed files with 16 additions and 9 deletions

View File

@ -191,7 +191,7 @@ cd proto && buf generate
```bash
# Start dev server
go run ./cmd/memos --mode dev --port 8081
go run ./cmd/memos --port 8081
# Run all tests
go test ./...
@ -458,7 +458,7 @@ cd web && pnpm lint
| Variable | Default | Description |
|----------|----------|-------------|
| `MEMOS_MODE` | `dev` | Mode: `dev`, `prod`, `demo` |
| `MEMOS_DEMO` | `false` | Enable demo mode |
| `MEMOS_PORT` | `8081` | HTTP port |
| `MEMOS_ADDR` | `` | Bind address (empty = all) |
| `MEMOS_DATA` | `~/.memos` | Data directory |
@ -564,7 +564,7 @@ Each plugin has its own README with usage examples.
## 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
- CSRF protection via SameSite cookies
- CORS enabled for all origins (configure for production)

View File

@ -57,14 +57,22 @@ func (p *Profile) Validate() error {
// Set default data directory if not specified
if p.Data == "" {
if p.Demo {
// In demo mode, use a temporary directory or current directory
// In demo mode, use current directory
p.Data = "."
} else {
// In production mode, use system directory
if runtime.GOOS == "windows" {
p.Data = filepath.Join(os.Getenv("ProgramData"), "memos")
} else {
p.Data = "/var/opt/memos"
// 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"
} 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 = "."
}
}
}
}

View File

@ -47,7 +47,6 @@ USER nonroot:nonroot
VOLUME /var/opt/memos
ENV TZ="UTC" \
MEMOS_MODE="prod" \
MEMOS_PORT="5230"
EXPOSE 5230

View File

@ -29,4 +29,4 @@ go build -o "$OUTPUT" ./cmd/memos
echo "Build successful!"
echo "To run the application, execute the following command:"
echo "$OUTPUT --mode dev"
echo "$OUTPUT"

View File

@ -174,10 +174,10 @@ To run with demo data:
```bash
# Start in demo mode
go run ./cmd/memos --mode demo --port 8081
go run ./cmd/memos --demo --port 8081
# Or use the binary
./memos --mode demo
./memos --demo
# Demo database location
./build/memos_demo.db