@@ -2,6 +2,7 @@ const assert = require('assert');
22const crypto = require ( 'crypto' ) ;
33const fs = require ( 'fs' ) ;
44const uuid = require ( 'uuid' ) ;
5+ const url = require ( 'url' ) ;
56const httph = require ( './http_helper.js' ) ;
67const addons = require ( './addons.js' ) ;
78const builds = require ( './builds.js' ) ;
@@ -70,6 +71,37 @@ function app_payload_to_response(payload) {
7071 } ;
7172}
7273
74+ // private
75+ function app_simple_payload_to_response ( payload ) {
76+ return {
77+ created_at : payload . created . toISOString ( ) ,
78+ description : payload . description ,
79+ id : payload . id ,
80+ labels : payload . labels ,
81+ maintenance : ! ! payload . disabled ,
82+ name : payload . app_key ,
83+ simple_name : payload . simple_name ,
84+ key : payload . app_key ,
85+ organization : {
86+ id : payload . org_uuid ,
87+ name : payload . org_name ,
88+ } ,
89+ preview : payload . preview ? {
90+ id : payload . preview ,
91+ } : null ,
92+ region : {
93+ id : payload . region_uuid ,
94+ name : payload . region_name ,
95+ } ,
96+ space : {
97+ id : payload . space_uuid ,
98+ name : payload . space_name ,
99+ } ,
100+ updated_at : payload . modified . toISOString ( ) ,
101+ web_url : payload . url ,
102+ } ;
103+ }
104+
73105// private
74106function app_postgres_to_response ( result ) {
75107 result . app_key = `${ result . app_name } -${ result . space_name } ` ;
@@ -79,6 +111,15 @@ function app_postgres_to_response(result) {
79111 return app_payload_to_response ( result ) ;
80112}
81113
114+ // private
115+ function app_simple_postgres_to_response ( result ) {
116+ result . app_key = `${ result . app_name } -${ result . space_name } ` ;
117+ result . simple_name = result . app_name ;
118+ result . id = result . app_uuid ;
119+ result . modified = result . updated ;
120+ return app_simple_payload_to_response ( result ) ;
121+ }
122+
82123// private
83124function check_payload ( payload ) {
84125 assert . ok (
@@ -102,7 +143,9 @@ const insert_app = query.bind(query, fs.readFileSync('./sql/insert_app.sql').toS
102143// private
103144const select_app_setup_by_app = query . bind ( query , fs . readFileSync ( './sql/select_app_setup_by_app.sql' ) . toString ( 'utf8' ) , null ) ;
104145const select_apps_query = fs . readFileSync ( './sql/select_apps.sql' ) . toString ( 'utf8' ) ;
146+ const select_apps_simple_query = fs . readFileSync ( './sql/select_apps_simple.sql' ) . toString ( 'utf8' ) ;
105147const select_apps = query . bind ( query , select_apps_query , app_postgres_to_response ) ;
148+ const select_apps_simple = query . bind ( query , select_apps_simple_query , app_simple_postgres_to_response ) ;
106149
107150// private
108151// const select_app_query = fs.readFileSync('./sql/select_app.sql').toString('utf8');
@@ -169,7 +212,6 @@ async function update(pg_pool, app_key, name, maintenance, description, labels,
169212 hook_updated . app . maintenance = app . disabled = app . maintenance = maintenance ;
170213 setTimeout ( ( ) => common . notify_hooks ( pg_pool , app . app_uuid , 'updated' , JSON . stringify ( hook_updated ) , user || 'System' ) , 10 ) ;
171214
172-
173215 let errors = false ;
174216 await Promise . all ( ( await common . formations_exists ( pg_pool , app . app_uuid ) ) . map ( async ( dyno_type ) => {
175217 try {
@@ -224,7 +266,7 @@ async function create(pg_pool, org_key, space_key, app_name, description, labels
224266 // determine the url for the application depending on its compliance.
225267 const id = uuid . v4 ( ) ;
226268 const created = new Date ( ) ;
227- const url = await common . determine_app_url ( pg_pool , space . tags , app_name , space . name , organization . name ) ;
269+ const uri = await common . determine_app_url ( pg_pool , space . tags , app_name , space . name , organization . name ) ;
228270 // create config set in alamo
229271 await common . alamo . config . set . create ( pg_pool , app_name , space . name ) ;
230272 // add the default port.
@@ -237,7 +279,7 @@ async function create(pg_pool, org_key, space_key, app_name, description, labels
237279 name : app_name ,
238280 space_uuid : space . space ,
239281 org_uuid : organization . org ,
240- url,
282+ url : uri ,
241283 description,
242284 labels,
243285 } ) ) ;
@@ -270,7 +312,7 @@ async function create(pg_pool, org_key, space_key, app_name, description, labels
270312 space_uuid : space . space ,
271313 space_name : space . name ,
272314 modified : created ,
273- url,
315+ url : uri ,
274316 space_tags : space . tags ,
275317 } ;
276318
@@ -427,7 +469,18 @@ async function del(pg_pool, app_key, elevated_access, user) {
427469
428470// public
429471async function http_list ( pg_pool , req , res /* regex */ ) {
430- const apps = await select_apps ( pg_pool , [ ] ) ;
472+ let apps ;
473+ try {
474+ const queryObject = url . parse ( req . url , true ) . query ;
475+ if ( queryObject && queryObject . simple ) {
476+ apps = await select_apps_simple ( pg_pool , [ ] ) ;
477+ } else {
478+ apps = await select_apps ( pg_pool , [ ] ) ;
479+ }
480+ } catch ( err ) {
481+ apps = await select_apps ( pg_pool , [ ] ) ;
482+ }
483+
431484 return httph . ok_response ( res , JSON . stringify ( apps ) ) ;
432485}
433486
0 commit comments