@@ -7,11 +7,12 @@ import session from 'express-session';
77import { createServer } from 'http' ;
88import routes from './api/routes/api' ;
99import commandExists from 'command-exists'
10+ import config from 'config'
1011import execa from 'execa'
1112import opn from 'opn'
1213
1314let params = process . argv ;
14- let port = 3000 ;
15+ let port = 57432 ;
1516let portIndex = params . indexOf ( '-port' ) ;
1617if ( portIndex != - 1 ) {
1718 let reg = / [ 0 - 9 ] + / ;
@@ -58,31 +59,52 @@ app.use(bodyParser.urlencoded({extended: false}));
5859app . use ( cookieParser ( ) ) ;
5960app . use ( express . static ( path . join ( __dirname , 'public' ) ) ) ;
6061let sess = {
61- secret : 'mydicebot987' ,
62- cookie : { } ,
62+ secret : 'mydicebot12323' ,
63+ cookie : {
64+ secure : false ,
65+ maxAge : 1000 * 60 * 30 ,
66+ httpOnly : true ,
67+ } ,
6368 resave : false ,
6469 saveUninitialized : false
6570}
66- if ( app . get ( 'env' ) === 'production' ) {
67- app . set ( 'trust proxy' , 1 ) ;
68- }
71+ app . set ( 'trust proxy' , 1 ) ;
6972app . use ( session ( sess ) )
7073routes ( app ) ;
7174
72- let url = 'http://127.0.0.1:' + port + '/login' ;
73- if ( [ 'win32' , 'darwin' ] . includes ( process . platform ) ) {
74- opn ( url , {
75- wait : false ,
76- app :browser
77- } )
78- } else {
79- try {
80- const xdgOpenExists = commandExists ( 'xdg-open' )
81- if ( ! xdgOpenExists ) {
82- throw new Error ( 'xdg-open does not exist' )
75+ if ( process . env . NODE_ENV == 'production' && typeof config . mydice == 'undefined' ) {
76+ config . mydice = { } ;
77+ config . mydice . auth = { } ;
78+ config . mydice . chat = { } ;
79+ config . mydice . oauth = { } ;
80+ config . mydice . oauth . github = { } ;
81+ config . mydice . oauth . google = { } ;
82+ config . mydice . oauth . steem = { } ;
83+ config . mydice . pkg = true ;
84+ config . mydice . auth . url = 'https://auth.mydicebot.com/' ;
85+ config . mydice . chat . url = 'https://chat.mydicebot.com/' ;
86+ config . mydice . oauth . github . url = 'https://github.com/login/oauth/authorize?client_id=9f8842af70978390f78d' ;
87+ config . mydice . oauth . google . url = 'https://accounts.google.com/o/oauth2/auth?response_type=code&access_type=offline&client_id=192445019791-rupf3vtns5708bhtpt1vrmbhqk817qrr.apps.googleusercontent.com&redirect_uri=http://localhost:57432/google/cb&scope=https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email' ;
88+ config . mydice . oauth . steem . url = 'https://app.steemconnect.com/oauth2/authorize?client_id=mydicebot&redirect_uri=http://localhost:57432/steem/cb&scope=login&response_type=code' ;
89+ }
90+
91+ console . log ( 'pkg:' , config . mydice . pkg ) ;
92+ if ( config . mydice . pkg ) {
93+ let url = 'http://localhost:' + port + '/login' ;
94+ if ( [ 'win32' , 'darwin' ] . includes ( process . platform ) ) {
95+ opn ( url , {
96+ wait : false ,
97+ app :browser
98+ } )
99+ } else {
100+ try {
101+ const xdgOpenExists = commandExists ( 'xdg-open' )
102+ if ( ! xdgOpenExists ) {
103+ throw new Error ( 'xdg-open does not exist' )
104+ }
105+ execa ( 'xdg-open' , [ url ] )
106+ } catch ( _ ) {
107+ log ( `Unable to open your browser automatically. Please open the following URI in your browser:\n\n${ oAuthURL } \n\n` )
83108 }
84- execa ( 'xdg-open' , [ url ] )
85- } catch ( _ ) {
86- log ( `Unable to open your browser automatically. Please open the following URI in your browser:\n\n${ oAuthURL } \n\n` )
87109 }
88110}
0 commit comments