Skip to content

Commit 3faa3a4

Browse files
committed
feat: exit early if the workdir does not exists; proper exit codes
1 parent a608993 commit 3faa3a4

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
const { send } = require('micro');
22
const { promisify } = require('util');
3+
const { existsSync } = require("fs")
34

45
const validateReq = require('./lib/validateReq');
56
const exec = promisify(require('child_process').exec);
67

8+
const workDir = process.env.NSW_WORK_DIR || '/var/www/html';
9+
const scriptName = process.env.NSW_SCRIPT_NAME || 'build';
10+
const timeout = process.env.NSW_TIMEOUT || 30 * 1000;
11+
712
// CRITICAL: exit early if no token is defined.
813
if (!process.env.NSW_TOKEN) {
914
console.error('NO TOKEN DEFINED, EXITING.');
10-
process.exit(1);
15+
process.exit(9);
1116
}
1217

13-
const workDir = process.env.NSW_WORK_DIR || '/var/www/html';
14-
const scriptName = process.env.NSW_SCRIPT_NAME || 'build';
15-
const timeout = process.env.NSW_TIMEOUT || 30 * 1000;
18+
// CRITICAL: exit early if the workDir does not exists
19+
if (!existsSync(workDir)) {
20+
console.error('WORKDIR DOES NOT EXISTS, EXITING.');
21+
process.exit(1);
22+
}
1623

1724
const handleErrors = fn => async (req, res) => {
1825
try {

0 commit comments

Comments
 (0)