Skip to content

Commit 3453b68

Browse files
author
mydicebot
committed
v190616
1 parent c8d7f37 commit 3453b68

File tree

7 files changed

+44101
-1876
lines changed

7 files changed

+44101
-1876
lines changed

src/app.js

+42-20
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import session from 'express-session';
77
import {createServer} from 'http';
88
import routes from './api/routes/api';
99
import commandExists from 'command-exists'
10+
import config from 'config'
1011
import execa from 'execa'
1112
import opn from 'opn'
1213

1314
let params = process.argv;
14-
let port = 3000;
15+
let port = 57432;
1516
let portIndex = params.indexOf('-port');
1617
if(portIndex != -1) {
1718
let reg = /[0-9]+/;
@@ -58,31 +59,52 @@ app.use(bodyParser.urlencoded({extended: false}));
5859
app.use(cookieParser());
5960
app.use(express.static(path.join(__dirname, 'public')));
6061
let 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);
6972
app.use(session(sess))
7073
routes(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
}

src/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
if (!process.env.NODE_ENV) {
2+
process.env.NODE_ENV = "production"
3+
}
4+
console.log('env:'+ process.env.NODE_ENV);
15
require('babel-core/register');
26
require('./app');
37

src/package.json

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"name": "mydicebot-190616",
3+
"version": "0.0.1",
4+
"description": "My Dice Bot",
5+
"main": "index.js",
6+
"pkg": {
7+
"assets": [
8+
"views/**/*",
9+
"public/**/*"
10+
],
11+
"scripts": [
12+
"public/**/*.js"
13+
]
14+
},
15+
"babel": {
16+
"presets": [
17+
"es2015-node",
18+
"stage-0"
19+
]
20+
},
21+
"bin": {
22+
"start": "./index.js"
23+
},
24+
"dependencies": {
25+
"babel-cli": "^6.24.1",
26+
"babel-core": "^6.24.1",
27+
"babel-plugin-transform-builtin-extend": "^1.1.2",
28+
"babel-preset-env": "^1.6.1",
29+
"babel-preset-es2015": "^6.24.1",
30+
"babel-preset-es2015-node": "^6.1.1",
31+
"babel-preset-stage-0": "^6.24.1",
32+
"bitcore-message": "^1.0.4",
33+
"body-parser": "^1.10.2",
34+
"command-exists": "^1.2.7",
35+
"config": "^1.28.1",
36+
"cookie-parser": "^1.3.3",
37+
"execa": "^1.0.0",
38+
"express": "^4.16.2",
39+
"formidable": "^1.2.1",
40+
"graphql-request": "^1.8.2",
41+
"isomorphic-fetch": "^2.2.1",
42+
"kdbxweb": "https://github.com/keeweb/kdbxweb.git",
43+
"morgan": "^1.5.1",
44+
"opn": "^5.4.0",
45+
"pug": "^2.0.3",
46+
"request": "^2.88.0",
47+
"pkg": "^4.3.7",
48+
"steem": "^0.7.1"
49+
},
50+
"devDependencies": {
51+
"babel-cli": "^6.24.1",
52+
"babel-core": "^6.24.1",
53+
"babel-plugin-transform-builtin-extend": "^1.1.2",
54+
"babel-preset-env": "^1.6.1",
55+
"babel-preset-es2015": "^6.24.1",
56+
"babel-preset-es2015-node": "^6.1.1",
57+
"babel-preset-stage-0": "^6.24.1",
58+
"body-parser": "^1.10.2",
59+
"config": "^1.28.1",
60+
"cookie-parser": "^1.3.3",
61+
"express": "^4.16.2",
62+
"express-session": "^1.16.1",
63+
"kdbxweb": "https://github.com/keeweb/kdbxweb.git",
64+
"isomorphic-fetch": "^2.2.1",
65+
"morgan": "^1.5.1",
66+
"pkg": "^4.3.7",
67+
"pug": "^2.0.3"
68+
},
69+
"scripts": {
70+
"test": "node test.js",
71+
"dev": "pm2-dev pm2.json",
72+
"start": "pm2-docker pm2.json"
73+
},
74+
"author": "mydicebot",
75+
"license": "MIT"
76+
}

0 commit comments

Comments
 (0)