A security camera application.
- Requirements
- Quick Start
- Detailed Setup
- Starting the Server
- Nginx Configuration
- Working With Android
- Node.js v22+ (install via
nvm, install yarn withcorepack) (Latest tested: v26.13.1) - ffmpeg v7+ (Latest tested: v8.1)
- Production:
- A reverse proxy like nginx to handle HTTPS (see configuration)
-
Configure files: Rename
config.example.json,greenlock.d/config.example.json, and.env.exampleby removing ".example" from the filenames.- Fill in
config.json,greenlock.d/config.json, and.envby reading comments and property names in the config/this README to know how to fill the values.
- Fill in
-
Run
yarn db:generateandyarn db:migrate:deployto set up the database.- At this point your should be able to run
yarn devto test in a development environment.
- At this point your should be able to run
-
Generate SSL certificates:
yarn generate:ssl. -
Build and start:
yarn build && yarn start. -
Access via your reverse-proxy (see nginx config)
- Serve the SSL certificates from
greenlock.d/live/YourWebsite.tld/(replaceYourWebsite.tldwith your website, of course)
- Serve the SSL certificates from
-
Configuration Files: Rename the following example configuration files, replacing placeholders with your real values:
Original file New file .env.example.envconfig.example.jsonconfig.jsongreenlock.d/config.example.jsongreenlock.d/config.json**If you don't already have SSL certificates, plan to use
greenlock.d/config.json. Otherwise, you can leave it as is if you don't plan to useyarn generate:ssl. -
Database: Run
yarn db:generateto initialize the database manager andyarn db:migrate:deployto set up the database tables. -
SSL Certificates: Use
yarn generate:sslto generate SSL (HTTPS) certificates after editinggreenlock.d/config.jsonwith greenlock-express.- This starts an ACME authentication server on ports 80/443 and terminates automatically after certificate renewal or a 40-second timeout.
- If you wish, you can instead use your own SSL certificates with your reverse-proxy (nginx) by pointing nginx to wherever those are located on your system.
-
Build: Run
yarn buildto compile the server and client. -
Reverse Proxy: Configure nginx or a similar reverse-proxy to proxy to
http://localhost:3000(port 3000 is Gander's default), using the SSL certificates generated ingreenlock.d/live/(or your own).
-
Development/Testing:
- Ensure
API_ENVandANDROID_ENVare set todevelopmentin.env. - Run
yarn dev. Ensure port3000(change by addingPORTto.env) is available for the server. The site should open in your preferred browser. If not, go to localhost:3000.
- Ensure
-
Production
- Ensure
API_ENVandANDROID_ENVare set toproductionin.env. - Run
yarn buildand thenyarn start. Ensure ports 80 and 443 are available for the reverse proxy. Access your site through the proxy.
- Ensure
# Gander HTTPS server configuration
# Redirect HTTP to HTTPS
server {
listen 80;
listen [::]:80;
# Change example.tld to your website's address (like example.com)
server_name example.tld;
return 301 https://$host$request_uri;
}
# HTTPS
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
# Change example.tld to your website's address (like example.com)
server_name example.tld;
# CHANGE these paths to include YOUR website's domain, NOT "example.tld"
ssl_certificate /path/to/gander/greenlock.d/live/example.tld/fullchain.pem;
ssl_certificate_key /path/to/gander/greenlock.d/live/example.tld/privkey.pem;
ssl_trusted_certificate /path/to/gander/greenlock.d/live/example.tld/fullchain.pem;
add_header Strict-Transport-Security "max-age=31536000;";
location / {
# You may have changed the port from the default of 3000 in .env
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
# If you use Cloudflare proxying, replace $remote_addr with $http_cf_connecting_ip
# See https://developers.cloudflare.com/support/troubleshooting/restoring-visitor-ips/restoring-original-visitor-ips/#nginx-1
# alternatively use ngx_http_realip_module
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}Android-specific configuration starts with configuring the Android section of variables in .env and running yarn android:sync. You should run this command every time you edit any files/configuration/dependencies in the web or android directories and plan to build the Android app.
You can then use VSCode Java extensions to manage the project, or open and build in the app in Android Studio (by running yarn android:open) once you retrieve google-services.json:
-
Click here to learn how to setup a Firebase project
- When prompted for a package name, copy exactly what you have set
ANDROID_APP_IDto in.env. - Important Note: Stop at step 3.1 - you should have just downloaded a
google-services.jsonfile.
- When prompted for a package name, copy exactly what you have set
-
Place a copy of the downloaded
google-services.jsonin both the project root (./) and./android/app/
To provide the most secure application possible, the Android app is integrated with the Firebase App Check Play Integrity API. A Google Play Console developer account ($25 one-time fee) is required for this to function, but you can remove the functionality from the app if you so please, noting that it increases the potential impact of XSS attacks.
-
Then, follow these steps to enable the Play Integrity API.
-
Set up the advanced AppCheck settings of the app you made while following step 3.
- If you aren't distributing on Play Store (likely), then you'll want to ignore
PLAY_RECOGNIZEDandLICENSEDwhile requiringMEETS_DEVICE_INTEGRITY.
- If you aren't distributing on Play Store (likely), then you'll want to ignore
-
Navigate to your project's Firebase service accounts and click "Generate a new private key". Download the JSON file, rename it to
security-cam-credentials.json, and place it in the project root. -
Build the Android app in
productionenvironment when generating a release APK, but when coding locally, usedevelopmentenv to make the app work properly in the Android Studio emulator.- Always run
yarn cap syncafter any changes to.env. - Run
yarn cap open androidto open the project in Android Studio automatically.
- Always run