@@ -13,10 +13,11 @@ const dns = require('dns');
13
13
const os = require ( 'os' ) ;
14
14
const bodyParser = require ( 'body-parser' ) ;
15
15
16
- /* Include helper functions */
16
+ /* Include helper functions and route handlers */
17
17
const pingUrl = require ( './services/ping' ) ; // Used by the status check feature, to ping services
18
18
const saveConfig = require ( './services/save-config' ) ; // Saves users new conf.yml to file-system
19
19
const printMessage = require ( './services/print-message' ) ; // Function to print welcome msg on start
20
+ const rebuild = require ( './services/rebuild-app' ) ; // A script to programmatically trigger a build
20
21
require ( './src/utils/ConfigValidator' ) ; // Include and kicks off the config file validation script
21
22
22
23
/* Checks if app is running within a container, from env var */
@@ -39,6 +40,7 @@ const printWelcomeMessage = () => {
39
40
} ) ;
40
41
} ;
41
42
43
+ /* Just console.warns an error */
42
44
const printWarning = ( msg , error ) => {
43
45
console . warn ( `\x1b[103m\x1b[34m${ msg } \x1b[0m\n` , error || '' ) ; // eslint-disable-line no-console
44
46
} ;
64
66
}
65
67
} )
66
68
// POST Endpoint used to save config, by writing conf.yml to disk
67
- . use ( '/api /save' , method ( 'POST' , ( req , res ) => {
69
+ . use ( '/config-manager /save' , method ( 'POST' , ( req , res ) => {
68
70
try {
69
71
saveConfig ( req . body , ( results ) => {
70
72
res . end ( results ) ;
@@ -73,10 +75,18 @@ try {
73
75
res . end ( JSON . stringify ( { success : false , message : e } ) ) ;
74
76
}
75
77
} ) )
78
+ // GET endpoint to trigger a build, and respond with success status and output
79
+ . use ( '/config-manager/rebuild' , ( req , res ) => {
80
+ rebuild ( ) . then ( ( response ) => {
81
+ res . end ( JSON . stringify ( response ) ) ;
82
+ } ) . catch ( ( response ) => {
83
+ res . end ( JSON . stringify ( response ) ) ;
84
+ } ) ;
85
+ } )
76
86
// Finally, initialize the server then print welcome message
77
87
. listen ( port , ( ) => {
78
88
try { printWelcomeMessage ( ) ; } catch ( e ) { printWarning ( 'Dashy is Starting...' ) ; }
79
89
} ) ;
80
90
} catch ( error ) {
81
- printWarning ( 'Sorry, an error occurred ' , error ) ;
91
+ printWarning ( 'Sorry, a critical error occurred ' , error ) ;
82
92
}
0 commit comments