Skip to content

Commit ca26d36

Browse files
committed
add host,port,domain into config
1 parent a7bb573 commit ca26d36

File tree

6 files changed

+13
-12
lines changed

6 files changed

+13
-12
lines changed

app.js

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ const config = require('./config');
44

55
const app = new Koa();
66

7-
app.keys = config.keys;
8-
97
app.use(require('@koa/cors')());
108
app.use(require('koa-bodyparser')());
119
app.use(require('koa-static')(path.join(__dirname, 'public')));

config.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ require('dotenv').config({
44
});
55

66
const PORT = process.env.PORT || 3000;
7-
const HOST = process.env.HOST || `http://localhost:${PORT}`;
7+
const HOST = process.env.HOST || '127.0.0.1';
8+
9+
const DOMAIN = process.env.DOMAIN || `http://${HOST}${PORT !== 80 ? ':' + PORT : ''}`;
810

911
module.exports = {
1012
port: PORT,
1113
host: HOST,
12-
keys: ['killer is Jim'],
14+
domain: DOMAIN,
1315
mongodb: {
1416
uri: (process.env.NODE_ENV === 'test')
1517
? 'mongodb://localhost/any-shop-test'
@@ -27,22 +29,22 @@ module.exports = {
2729
github: {
2830
app_id: process.env.GITHUB_APP_ID || 'github_app_id',
2931
app_secret: process.env.GITHUB_APP_SECRET || 'github_app_secret',
30-
callback_uri: `${HOST}/oauth/github`,
32+
callback_uri: `${DOMAIN}/oauth/github`,
3133
options: {
3234
scope: ['user:email'],
3335
},
3436
},
3537
yandex: {
3638
app_id: process.env.YANDEX_APP_ID || 'yandex_app_id',
3739
app_secret: process.env.YANDEX_APP_SECRET || 'yandex_app_secret',
38-
callback_uri: `${HOST}/oauth/yandex`,
40+
callback_uri: `${DOMAIN}/oauth/yandex`,
3941
options: {
4042
},
4143
},
4244
vkontakte: {
4345
app_id: process.env.VKONTAKTE_APP_ID || 'vkontakte_app_id',
4446
app_secret: process.env.VKONTAKTE_APP_SECRET || 'vkontakte_app_secret',
45-
callback_uri: `${HOST}/oauth/vkontakte`,
47+
callback_uri: `${DOMAIN}/oauth/vkontakte`,
4648
options: {
4749
scope: ['email'],
4850
},

controllers/orders.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports.checkout = async function checkout(ctx, next) {
2020
address: ctx.user.email,
2121
},
2222
subject: 'Подтверждение заказа',
23-
locals: {href: config.host, product: product.title, price: `${product.price}₽`},
23+
locals: {href: config.domain, product: product.title, price: `${product.price}₽`},
2424
template: 'order',
2525
});
2626

controllers/registration.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports.register = async (ctx, next) => {
2020
address: user.email,
2121
},
2222
subject: 'Подтвердите почту',
23-
locals: {href: `${config.host}/confirm/${verificationToken}`},
23+
locals: {href: `${config.domain}/confirm/${verificationToken}`},
2424
template: 'confirmation',
2525
});
2626

ecosystem.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
"instances": 1,
88
"env": {
99
"NODE_ENV": "production",
10+
"HOST": "0.0.0.0",
1011
"PORT": 80,
11-
"HOST": "http://nodejs-shop.javascript.info"
12+
"DOMAIN": "http://nodejs-shop.javascript.info"
1213
}
1314
}
1415
]

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ const config = require('./config');
33
const socket = require('./libs/socket');
44
const logger = require('./libs/logger');
55

6-
const server = app.listen(config.port, () => {
7-
logger.info(`App is running on http://localhost:${config.port}`);
6+
const server = app.listen(config.port, config.host, () => {
7+
logger.info(`App is running on ${config.host}:${config.port}`);
88
});
99

1010
socket(server);

0 commit comments

Comments
 (0)