Skip to content

Latest commit

 

History

History

listener

Listener example

Web API for Send notifications to Google Nest

Setup

pnpm install
cp .env.example .env

Development

pnpm dev
curl -X POST -H "Accept: application/json" -H 'Content-Type: application/json' -d '{"deviceName":"rachael","text":"Hello world","language":"en"}' http://localhost:3000/notifications
curl -X POST -H "Accept: application/json" -H 'Content-Type: application/json' -d '{"deviceName":"rachael","text":"日本語でおk","language":"ja"}' http://localhost:3000/notifications

Testing

pnpm test

Production

Start server

pnpm build
pnpm start

Zero downtime reload

pnpm reload

Restart server

pnpm restart

Stop server

pnpm stop

Show process list

npx pm2 list
┌─────┬─────────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name                    │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼─────────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0   │ google-nest-notifier    │ default     │ 0.0.2   │ cluster │ 84050    │ 4s     │ 2    │ online    │ 0%       │ 48.1mb   │ pi       │ disabled │
└─────┴─────────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘

Show logs

pnpm logs
pnpm logs --lines 50

Use ngrok (optional)

You can use ngrok.

Sign up ngrok and set your token to .env so that your tunnels don't time out.

pnpm start
pnpm logs

Copy your ngrok url from pm2 logs.

Forwarding: https://xxxxxxxx.ngrok-free.app
-> http://localhost:3000
curl -X POST -H "Accept: application/json" -H 'Content-Type: application/json' -d '{"deviceName":"rachael","text":"Hello world","language":"en"}' https://xxxxxxxx.ngrok-free.app/notifications

Fix URL with AWS API Gateway (optional)

  • Create AWS API Gateway
  • Set your AWS API Gateway info to .env
pnpm start
pnpm logs

Copy your AWS API Gateway url from pm2 logs.

HttpProxy: https://xxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/prod/notifications
-> https://xxxxxxxx.ngrok-free.app/notifications
-> http://localhost:3000/notifications
curl -X POST -H "Accept: application/json" -H 'Content-Type: application/json' -d '{"deviceName":"rachael","text":"Hello world","language":"en"}' https://xxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/prod/notifications

Deployment

Setup

pnpm deploy:setup
pnpm deploy:only
pnpm deploy:install:pnpm
pnpm deploy:install:google-nest-notifier

Set .env

cp .env.example .env.production

Edit .env.production

scp .env.production {USER}@{HOST}:/var/www/google-nest-notifier/current/examples/listener/.env
scp .env.production pi@raspberrypi:/var/www/google-nest-notifier/current/examples/listener/.env

Build & Start

pnpm deploy:build
pnpm deploy:start

deploy

pnpm deploy

logs

pnpm deploy:logs