@@ -21,24 +21,28 @@ router.post('/createDB', function (req,res) {
2121 // If user does exist send error response.
2222 res . send ( "User already exists, please supply new username." ) . status ( 409 ) ;
2323 } catch ( err ) {
24+
2425 // Handle duplicate database name.
2526 try {
2627 db . _createDatabase ( dbName ) ;
2728 } catch ( err ) {
2829 res . send ( "Database already exists or invalid name supplied, please supply new dbName." ) . status ( 400 ) ;
2930 }
31+
3032 users . save ( username , password , true ) ;
33+ let hostname = req . hostname
34+ let port = req . port
35+
3136 // Grants user access only to newly created database
3237 users . grantDatabase ( username , dbName , 'rw' ) ;
33- res . send ( { dbName, username, password} ) ;
38+ res . send ( { dbName, username, password, hostname , port } ) ;
3439 }
3540} )
3641. body ( joi . object ( ) . required ( ) , 'Creates a new database, optionally provide dbName, username, or password ' )
3742. response ( joi . object ( ) . required ( ) , 'Returns database name, username, and password.' )
3843. summary ( 'Creates a database and returns name and login credentials.' )
3944. description ( 'Creates a database with potentially randomly generated dbName, username, and password. ' ) ;
4045
41-
4246function randomStringGenerator ( ) {
4347 // Database name must start with letter.
4448 return "ML" + Math . random ( ) . toString ( 36 ) . substring ( 2 , 15 ) + Math . random ( ) . toString ( 36 ) . substring ( 2 , 15 ) ;
0 commit comments