https://github.com/lipp/now-is-production
Checks if your `now` deployment is the production deployment
https://github.com/lipp/now-is-production
Last synced: 5 months ago
JSON representation
Checks if your `now` deployment is the production deployment
- Host: GitHub
- URL: https://github.com/lipp/now-is-production
- Owner: lipp
- License: mit
- Created: 2016-10-13T08:36:10.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-10-13T08:54:33.000Z (almost 10 years ago)
- Last Synced: 2025-06-02T06:13:08.586Z (about 1 year ago)
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# The problem
Depending if your deployment is staging or production, your service might behave differently.
When using [now](https://zeit.co/now), your deployment gets a "random" url when deployed initially.
If you want your deployment to go production, a `now alias` is created.
After re-eploying your service, the old deployment may have to do some cleanup or shutdown (e.g. closing socket connections).
# The solution
This module periodically polls if the running deployment (NOW_URL env) has an alias to the production url.
```js
const nowIsProduction = require('now-is-production')
const now = nowClient('YOUR TOKEN')
const listener = nowIsProduction({
api: now,
productionUrl: 'live.yourservice.com',
checkInterval: 30000 // 30secs
})
listener.on('staging', (wasProduction) => {
if (wasProduction) {
// close real DB connection
// process.exit(0)
} else {
// connect dummy DB
}
})
listener.on('production', (wasStaging) => {
if (wasStaging) {
// close dummy DB
}
// connect real DB
})
```