Sam/Deployment Fixes - #29
Conversation
6817af3 to
5660cf8
Compare
Remove unused config fields and parameterize config with optional ENV.
5660cf8 to
b2c00d2
Compare
Errors caught from main that are not handled should be logged and the process should be exited.
Use pino and pino-pretty for fast and simple logging. Use an appropriate log level for exceptions.
| if (!/^\d+(?:.\d+)$/.test(numStr)) { | ||
| throw TypeError('Expected number string') | ||
| } | ||
| return numStr |
There was a problem hiding this comment.
You should do it as:
const clean = Number(asString(raw))
if (isNaN(clean)) throw new TypeError('Expected number string')
return cleanThat way the result is a proper number. When I added @types/express to the repo, this string turned into a type error.
There was a problem hiding this comment.
From our discussion: no need for the change because type transformation is handled outside of the cleaner in this context (line 39 for httpPort)
| // Couch | ||
| couchDbFullpath: asOptional( | ||
| asString, | ||
| `http://${env.COUCH_USERNAME}:${env.COUCH_PASSWORD}@${env.COUCH_HOSTNAME}:${env.COUCH_PORT}` | ||
| ), | ||
| // App Server | ||
| httpPort: asOptional(asNumber, parseInt(env.HTTP_PORT)), | ||
| // Info Server | ||
| infoServerAddress: asOptional(asString, env.INFO_SERVER_ADDRESS), | ||
| infoServerApiKey: asOptional(asString, env.INFO_SERVER_API_KEY), |
There was a problem hiding this comment.
This whole section will become a merge conflict when you rebase your PR - I already cleaned this section up.
| { | ||
| "apps": [ | ||
| { | ||
| "name": "server", | ||
| "script": "lib/indexApi.js", | ||
| "error_file": "logs/server/error.log", | ||
| "out_file": "logs/server/out.log" | ||
| } | ||
| ] | ||
| } |
There was a problem hiding this comment.
The server should have a real name, and the output should continue going to /var/log:
{
"apps": [
{
"name": "logsServer",
"script": "./lib/indexApi.js",
"out_file": "/var/log/logsServer.log"
}
]
}There was a problem hiding this comment.
Actually, on the production box it's /var/log/logsApi.log, but I think logsServer is a better name.
There was a problem hiding this comment.
Also, we should add this to the readme:
Manage server using pm2
First, install pm2 to run at startup:
yarn global add pm2
pm2 startup # Then do what it saysNext, tell pm2 how to run the server script:
# install:
pm2 start pm2.json
pm2 save
# check status:
pm2 monit
tail -f /var/log/logsServer.log
# manage:
pm2 restart logsServer
pm2 reload logsServer
pm2 stop logsServer| .vscode/ | ||
|
|
||
| # Logs: | ||
| logs/ No newline at end of file |
There was a problem hiding this comment.
Not necessary if the output goes to /var/log
fa42ba8 to
4e951b7
Compare
This is a draft until successfully testing on a new test droplet