Skip to content

Commit

Permalink
feat: IS_PROXY option
Browse files Browse the repository at this point in the history
  • Loading branch information
popstas committed Jun 27, 2018
1 parent b3d75e7 commit acd76ca
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
обходя ограничения. Вы можете собрать свою версию сами или зайти на https://dialogs.home.popstas.ru,
она с серверной частью, но только для внешних запросов к навыкам, все данные по-прежнему хранятся в localStorage.

При сборке за это отвечает переменная окружения `IS_PROXY`, если она равна единице, `1`, то запросы будут идти через сервер.


## Установка
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ services:
build: .
environment:
BASE_URL: https://dialogs.home.popstas.ru # default http://localhost:3000
IS_PROXY: 1
ports:
- 3856:3000
3 changes: 2 additions & 1 deletion nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module.exports = {
// mode: 'spa',
env: {
baseUrl: process.env.BASE_URL || 'http://localhost:3000',
production: process.env.NODE_ENV === "production"
production: process.env.NODE_ENV === "production",
isProxy: process.env.IS_PROXY === "1"
},

modules: [
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"scripts": {
"dev": "cross-env HOST=0.0.0.0 PORT=3000 nuxt",
"dev-proxy": "cross-env IS_PROXY=1 HOST=0.0.0.0 PORT=3000 nuxt",
"dev-debug": "node --inspect node_modules/.bin/nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
Expand Down
2 changes: 1 addition & 1 deletion scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -eu

rm -rf dist
npm run generate
IS_PROXY=0 npm run generate
cd dist
git init
git add -A
Expand Down
12 changes: 9 additions & 3 deletions store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const state = () => ({
homepage: pjson.homepage,

// app state
isProxy: process.env.isProxy,
userId: '',
sessionId: '',
webhookURL: ''
Expand Down Expand Up @@ -81,8 +82,12 @@ export const actions = {

try {
if (state.webhookURL) {
let responseData = await this.$axios.$post('/api/request', axiosData);
// let responseData = await this.$axios.$post(state.webhookURL, data);
let responseData;
if (state.isProxy) {
responseData = await this.$axios.$post('/api/request', axiosData);
} else {
responseData = await this.$axios.$post(state.webhookURL, data);
}

commit(ADD_MESSAGE, {
text: responseData.response.text,
Expand Down Expand Up @@ -113,7 +118,8 @@ export const actions = {

commit(SET_WEBHOOK_URL, url);
commit(ADD_MESSAGE, {
text: 'Используется навык по адресу ' + url,
text:
'Используется навык по адресу ' + url + (state.isProxy ? ', через прокси' : ', без прокси'),
author: ''
});
localStorage.setItem('webhookURL', url);
Expand Down

0 comments on commit acd76ca

Please sign in to comment.