2016-09-28 23:54:19 +02:00
#!/usr/bin/env node
2020-04-14 22:29:11 +02:00
2016-09-28 23:54:19 +02:00
'use strict' ;
2016-09-29 18:10:23 +02:00
process . env . NODE _ENV = 'production' ;
2019-06-14 18:10:38 +02:00
const fs = require ( 'fs' ) ;
2016-09-28 23:54:19 +02:00
2020-04-14 22:29:11 +02:00
const { argv } = require ( 'yargs' )
2016-12-03 13:45:22 +01:00
. usage ( '$0 [options]' )
. env ( true )
. option ( 'port' , {
alias : 'p' ,
describe : 'The HTTP port you want to start unleash on' ,
demand : false ,
default : 4242 ,
type : 'number' ,
} )
2018-05-06 10:23:53 +02:00
. option ( 'host' , {
alias : 'l' ,
describe : 'The HTTP address the server will accept connections on.' ,
demand : false ,
type : 'string' ,
} )
2016-12-03 13:45:22 +01:00
. option ( 'databaseUrl' , {
alias : 'd' ,
2017-06-28 14:10:32 +02:00
describe :
2019-06-14 18:10:38 +02:00
'The full databaseUrl to connect to, including username and password. Either databaseUrl or databaseUrlFile is required.' ,
demand : false ,
type : 'string' ,
} )
. option ( 'databaseUrlFile' , {
alias : 'f' ,
describe :
'The full path to a file containing the full database url to connect to, including username and password. When this option is supplied, it takes precedence over databaseUrl.' ,
demand : false ,
2016-12-03 13:45:22 +01:00
type : 'string' ,
2019-02-01 08:06:02 +01:00
} )
2019-06-18 20:34:08 +02:00
. check ( args => ! ! ( args . databaseUrl || args . databaseUrlFile ) )
2019-02-01 08:06:02 +01:00
. option ( 'databaseSchema' , {
alias : 's' ,
describe : 'The database schema to use' ,
default : 'public' ,
demand : false ,
type : 'string' ,
2020-04-14 22:29:11 +02:00
} ) ;
const serverImpl = require ( '../lib/server-impl.js' ) ;
2016-12-03 13:45:22 +01:00
2019-06-14 18:10:38 +02:00
if ( argv . databaseUrlFile ) {
2019-06-18 20:34:08 +02:00
argv . databaseUrl = fs . readFileSync ( argv . databaseUrlFile , 'utf8' ) ;
2019-06-14 18:10:38 +02:00
delete argv . databaseUrlFile ;
}
2017-06-28 14:10:32 +02:00
serverImpl
. start ( argv )
2018-05-06 12:17:46 +02:00
. then ( instance => {
2018-05-06 12:50:43 +02:00
const address = instance . server . address ( ) ;
2020-04-14 22:29:11 +02:00
// eslint-disable-next-line no-console
2017-06-28 14:10:32 +02:00
console . log (
2020-04-14 22:29:11 +02:00
` Unleash started on http:// ${ address . address } : ${ address . port } ` ,
2018-05-06 12:17:46 +02:00
) ;
} )
2020-04-14 22:29:11 +02:00
// eslint-disable-next-line no-console
2017-06-28 14:10:32 +02:00
. catch ( console . err ) ;