From 5dc35a7c4af2ea9b6fd53fecd6591d37b9834f51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=88=98=EB=B9=88?= <57705512+MOBUMIN@users.noreply.github.com> Date: Sun, 13 Feb 2022 19:34:17 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20env=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + package-lock.json | 40 ++++++++++++++++++++++++++++++++++++++++ package.json | 4 +++- rollup.config.js | 8 ++++++++ src/common/Variable.js | 5 +++-- src/pages/Home.svelte | 3 ++- src/pages/Setting.svelte | 1 - src/store/user.js | 4 ++-- 8 files changed, 59 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 3fdf3e1..81c007e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ # /public/build/ .DS_Store +.env diff --git a/package-lock.json b/package-lock.json index 1a94e12..27b778e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,9 @@ "devDependencies": { "@rollup/plugin-commonjs": "^17.0.0", "@rollup/plugin-node-resolve": "^11.0.0", + "@rollup/plugin-replace": "^3.1.0", "autoprefixer": "^10.4.2", + "dotenv": "^16.0.0", "node-sass": "^7.0.1", "postcss": "^8.4.6", "rollup": "^2.67.0", @@ -140,6 +142,19 @@ "rollup": "^1.20.0||^2.0.0" } }, + "node_modules/@rollup/plugin-replace": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-replace/-/plugin-replace-3.1.0.tgz", + "integrity": "sha512-pA3XRUrSKybVYqmH5TqWNZpGxF+VV+1GrYchKgCNIj2vsSOX7CVm2RCtx8p2nrC7xvkziYyK+lSi74T93MU3YA==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^3.1.0", + "magic-string": "^0.25.7" + }, + "peerDependencies": { + "rollup": "^1.20.0 || ^2.0.0" + } + }, "node_modules/@rollup/pluginutils": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz", @@ -839,6 +854,15 @@ "node": ">=8" } }, + "node_modules/dotenv": { + "version": "16.0.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.0.tgz", + "integrity": "sha512-qD9WU0MPM4SWLPJy/r2Be+2WgQj8plChsyrCNQzW/0WjvcJQiKQJ9mH3ZgB3fxbUUxgc/11ZJ0Fi5KiimWGz2Q==", + "dev": true, + "engines": { + "node": ">=12" + } + }, "node_modules/ecc-jsbn": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", @@ -3742,6 +3766,16 @@ "resolve": "^1.19.0" } }, + "@rollup/plugin-replace": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-replace/-/plugin-replace-3.1.0.tgz", + "integrity": "sha512-pA3XRUrSKybVYqmH5TqWNZpGxF+VV+1GrYchKgCNIj2vsSOX7CVm2RCtx8p2nrC7xvkziYyK+lSi74T93MU3YA==", + "dev": true, + "requires": { + "@rollup/pluginutils": "^3.1.0", + "magic-string": "^0.25.7" + } + }, "@rollup/pluginutils": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz", @@ -4287,6 +4321,12 @@ "integrity": "sha512-reYkTUJAZb9gUuZ2RvVCNhVHdg62RHnJ7WJl8ftMi4diZ6NWlciOzQN88pUhSELEwflJht4oQDv0F0BMlwaYtA==", "dev": true }, + "dotenv": { + "version": "16.0.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.0.tgz", + "integrity": "sha512-qD9WU0MPM4SWLPJy/r2Be+2WgQj8plChsyrCNQzW/0WjvcJQiKQJ9mH3ZgB3fxbUUxgc/11ZJ0Fi5KiimWGz2Q==", + "dev": true + }, "ecc-jsbn": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", diff --git a/package.json b/package.json index f4cf55d..35b78fb 100644 --- a/package.json +++ b/package.json @@ -6,12 +6,14 @@ "build": "rollup -c", "dev": "rollup -c -w", "start": "sirv public --no-clear", - "release": "git push origin `git subtree split --prefix public/ main`:gh-pages --force" + "release": "git push origin `git subtree split --prefix public/ main`:gh-pages --force" }, "devDependencies": { "@rollup/plugin-commonjs": "^17.0.0", "@rollup/plugin-node-resolve": "^11.0.0", + "@rollup/plugin-replace": "^3.1.0", "autoprefixer": "^10.4.2", + "dotenv": "^16.0.0", "node-sass": "^7.0.1", "postcss": "^8.4.6", "rollup": "^2.67.0", diff --git a/rollup.config.js b/rollup.config.js index d510e38..df101ca 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -5,7 +5,10 @@ import livereload from 'rollup-plugin-livereload'; import { terser } from 'rollup-plugin-terser'; import css from 'rollup-plugin-css-only'; import sveltePreprocess from 'svelte-preprocess'; +import replace from '@rollup/plugin-replace'; +import dotenv from 'dotenv'; +dotenv.config(); const production = !process.env.ROLLUP_WATCH; function serve() { @@ -38,6 +41,11 @@ export default { file: 'public/build/bundle.js' }, plugins: [ + replace({ + ENV_API_URL: JSON.stringify(process.env.API_URL), + ENV_CALLBACK_URL: production? JSON.stringify(process.env.CALLBACK_URL) : JSON.stringify(process.env.CALLBACK_URL_LOCAL), + ENV_GIT_URL: JSON.stringify(process.env.GIT_URL) + }), svelte({ compilerOptions: { // enable run-time checks when not in production diff --git a/src/common/Variable.js b/src/common/Variable.js index 7ae4ae4..10725a1 100644 --- a/src/common/Variable.js +++ b/src/common/Variable.js @@ -1,3 +1,4 @@ -export const GIT_URL = 'https://github.com'; -export const API_URL = 'https://grabit.duckdns.org/api'; +export const GIT_URL = ENV_GIT_URL; +export const API_URL = ENV_API_URL; +export const CALLBACK_URL = ENV_CALLBACK_URL; export const ACCESS_TOKEN = 'accessToken'; \ No newline at end of file diff --git a/src/pages/Home.svelte b/src/pages/Home.svelte index 9afc455..a45713b 100644 --- a/src/pages/Home.svelte +++ b/src/pages/Home.svelte @@ -7,6 +7,7 @@ import { user, getUser } from '../store/user.js'; import { changeTab } from '../store/page'; import { challengeList } from '../store/challenge.js'; + import { ACCESS_TOKEN } from '../common/Variable'; let grass_list = new Array(365); @@ -17,7 +18,7 @@ // TODO: 유저별로 home을 만들지 자기 home만 보이게 할 것인지 회의 필요 beforeUpdate(() => { if (!$user){ - if(localStorage.getItem('accessToken')) getUser(); + if(localStorage.getItem(ACCESS_TOKEN)) getUser(); else push('/login'); } }); diff --git a/src/pages/Setting.svelte b/src/pages/Setting.svelte index 1480db7..ab81a28 100644 --- a/src/pages/Setting.svelte +++ b/src/pages/Setting.svelte @@ -5,7 +5,6 @@ let activeItem = -1; function onClickItem(i) { activeItem = i; - console.log(activeItem) } function setActive(i) { if(i === activeItem) return true; diff --git a/src/store/user.js b/src/store/user.js index 2095cec..4459e0e 100644 --- a/src/store/user.js +++ b/src/store/user.js @@ -1,11 +1,11 @@ import { writable } from 'svelte/store'; -import { ACCESS_TOKEN } from '../common/Variable'; +import { ACCESS_TOKEN, CALLBACK_URL } from '../common/Variable'; import { fetchGet, fetchGetRedirectUrl, getQueryUri } from '../common/fetch'; export const user = writable(null); export async function login() { - await fetchGetRedirectUrl(`oauth2/authorization/github?${getQueryUri({ 'redirect_uri' : 'http://localhost:5000/#/redirect'})}`, {redirect: 'manual'}) + await fetchGetRedirectUrl(`oauth2/authorization/github?${getQueryUri({ 'redirect_uri' : CALLBACK_URL+'#/redirect'})}`, {redirect: 'manual'}) } export function logout() {