๐Ÿ’ช๐Ÿฟ gain-muscle | ๋“๊ทผ : Development Log

protect-meยท2021๋…„ 7์›” 25์ผ
0
post-thumbnail

์ ์ง„์  ๊ณผ๋ถ€ํ•˜๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ๊ทผ๋ ฅ ์šด๋™ ๊ธฐ๋ก ์›น์•ฑ ๋“๊ทผ ๐Ÿง™๐Ÿปโ€โ™‚
Github(front): https://github.com/protect-me/gm-front
Github(back): https://github.com/protect-me/gm-back

๐Ÿงฉ Specs

Vue2 + Vuetify + Express + MySQL
(Heroku๋ฅผ ํ†ตํ•œ ๋ฐฐํฌ ์ž‘์—… ์ค‘)

๐Ÿ“ผ ์œ ํŠœ๋ธŒ ์‹œ์—ฐ ์˜์ƒ ํ”Œ๋ ˆ์ด๋ฆฌ์ŠคํŠธ

๐Ÿ‘‰๐Ÿป ๋“๊ทผ 2๋ถ„๋งŒ์— ํ›‘์–ด๋ณด๊ธฐ (x2๋ฐฐ์† ์‹œ์ฒญ ๊ถŒ์žฅ)








๐ŸŒ‘ Set Front-End Environment | ํ”„๋ก ํŠธ์—”๋“œ ํ™˜๊ฒฝ์„ค์ •

๐Ÿš€ Create Project Directory | ํ”„๋กœ์ ํŠธ ๊ฒฝ๋กœ ์ƒ์„ฑ

mkdir gain-muscle : create gain-muscle folder
cd gain-muscle : change directory

gain-muscle ๊ฒฝ๋กœ๋Š” ์ดํ•˜ root๋กœ ๋ช…๋ช…ํ•จ.

๐Ÿš€ Create Vue Project with Vue-CLI | Vue-CLI๋กœ Vue ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜๊ธฐ

$ vue create frontend : create Vue project with vue-cli(set in frontend folder)

Vue CLI v4.5.13
? Please pick a preset: Manually select features
? Check the features needed for your project: Choose Vue version, Babel, Router, Vuex, Linter
? Choose a version of Vue.js that you want to start the project with 2.x
? Use history mode for router? (Requires proper server setup for index fallback in production) Yes
? Pick a linter / formatter config: Basic
? Pick additional lint features: Lint on save
? Where do you prefer placing config for Babel, ESLint, etc.? In package.json
? Save this as a preset for future projects? No

$ cd frontend : change directory
$ yarn serve : run project

http://localhost:8080/ : served local App URL

๐Ÿš€ Set Vuetify | ๋ทฐํ‹ฐํŒŒ์ด ์„ค์ •

$ vue add vuetify : add vuetify to project

? Choose a preset: Configure (advanced)
? Use a pre-made template? (will replace App.vue and HelloWorld.vue) Yes
? Use custom theme? No
? Use custom properties (CSS variables)? No
? Select icon font Material Design Icons
? Use fonts as a dependency (for Electron or offline)? No
? Use a-la-carte components? Yes
? Select locale English

๐ŸŒ’ Set Back-End Environment | ๋ฐฑ์—”๋“œ ํ™˜๊ฒฝ์„ค์ •

๐Ÿš€ install express | ์ต์Šคํ”„๋ ˆ์Šค ์„ค์น˜

$ npm install -g express-generator
or $ yarn global add express-generator : install express-generator

$ express --view=pug backend : create express in backend folder
$ cd backend : change directory
$ npm install : install dependencies
$ npm start : run the app

http://localhost:3000/ : served local App URL(back end)

Ctrl + C : stop server


๐ŸŒ“ Install MySQL && Connect MySQLWorkbench

๐Ÿš€ create Schema

schema name: gain_muscle
characterset: utf8
collation: utf8_general_ci

(์ƒˆ ์ฟผ๋ฆฌ ๋ฒ„ํŠผ - ํŽ˜์ด์ง€+)

  • Query
use gain_muscle;
CREATE TABLE users ( 
   userid VARCHAR(255) NOT NULL , 
   password VARCHAR(255) NULL , 
   name VARCHAR(255) NULL , 
PRIMARY KEY (userid) );

(์ฟผ๋ฆฌ ์‹คํ–‰ ๋ฒ„ํŠผ - ๋ฒˆ๊ฐœ๋ชจ์–‘)


๐ŸŒ” Connect Front <-> Back

๐Ÿš€ vue.config.js

root > frontend > vue.config.js

module.exports = { 
    devServer: { //โ‘  api ์š”์ฒญ์ด ์žˆ์„๋•Œ ์–ด๋””์—์„œ ์ฒ˜๋ฆฌํ• ์ง€๋ฅผ ์„ค์ •
      proxy: { 
        '/api': { 
          target: 'http://localhost:3000/api',
          changeOrigin: true, 
          pathRewrite: { 
            '^/api': ''
          } 
        } 
      } 
    },
    outputDir: '../backend/public',  //โ‘ก ๋ฐฐํฌ ํŒŒ์ผ์˜ ์œ„์น˜๋ฅผ ์ง€์ •
  }

$ cd frontend
$ npm run build
$ cd ../backend
$ npm start

์œ„์™€ ๊ฐ™์ด Express ์„œ๋ฒ„๋ฅผ ์‹คํ–‰์‹œํ‚ค๋ฉด, localhost:3000 ํŽ˜์ด์ง€๋„
localhost:8080 ํŽ˜์ด์ง€์™€ ๋™์ผํ•œ ํ™”๋ฉด์œผ๋กœ ๋ณ€๊ฒฝ ๋œ ๊ฒƒ์„ ํ™•์ธ

๐Ÿš€ install mysql, bcryptjs

root > backend
$ npm install mysql --save : install mysql
$ npm install bcryptjs --save : install bcryptjs, ์•”ํ˜ธํ™” ํ•ด์‹œ ํ•จ์ˆ˜

๐Ÿš€ backend app.js

root > backend > app.js
*connection ๊ฐ์ฒด๋Š” ์„ค์น˜ํ•œ DB ํ™˜๊ฒฝ์— ๋งž๋Š” ๊ฐ’์œผ๋กœ ๋ณ€๊ฒฝ(ex. password: '1234')

var mysql = require('mysql');
// Connection ๊ฐ์ฒด ์ƒ์„ฑ 
var connection = mysql.createConnection({
  host: 'localhost',
  port: 3306,
  user: 'root',   
  password: 'password',
  database: 'pwa_crud'  
});  
// Connect
connection.connect(function (err) {   
  if (err) {     
    console.error('mysql connection error');     
    console.error(err);     
    throw err;   
  } 
});

$ npm start: backend ์„œ๋ฒ„๊ฐ€ ์ž˜ ๋Œ์•„๊ฐ€๋Š”์ง€ ํ™•์ธ
*์—๋Ÿฌ ๋ฐœ์ƒ ์‹œ connection ๊ฐ์ฒด ์ •๋ณด๋ฅผ ์ •ํ™•ํ•˜๊ฒŒ ์ž…๋ ฅํ–ˆ๋Š”์ง€ ํ™•์ธ

๐Ÿš€ install axios

  • API ํ†ต์‹ ์„ ์œ„ํ•ด frontend/backend ๊ฐ๊ฐ์˜ ๊ฒฝ๋กœ์—์„œ axios๋ฅผ ์„ค์น˜ํ•จ.

$ cd frontendnpm install axios --save
$
$ cd ../backend
$ npm install axios --save

  • root > frontend > src > main.js
(...)
import axios from 'axios'
(...)
Vue.prototype.$http = axios;
(...)

๐Ÿšจ error

rooot > front
$ npm run serve or $ npm run build ๋ช…๋ น ์‹œ, ์•„๋ž˜์™€ ๊ฐ™์€ ์—๋Ÿฌ

Failed to compile with 144 errors                                                         19:04:52

These dependencies were not found:

* core-js/modules/es.array.concat.js in ./node_modules/vuetify/lib/components/VGrid/VContainer.js, ./node_modules/vuetify/lib/components/VProgressCircular/VProgressCircular.js and 6 others
* core-js/modules/es.array.fill.js in ./node_modules/vuetify/lib/util/helpers.js
* core-js/modules/es.array.filter.js in ./node_modules/@babel/runtime/helpers/esm/objectSpread2.js, ./node_modules/vuetify/lib/components/VGrid/VContainer.js and 1 other

$ npm install --save core-js: core-js ์„ค์น˜
(ํด๋ฆฌํ•„ ๋ฌธ์ œ, ๋ฐ”๋ฒจ 7.4 ์ด์ƒ ๋ฒ„์ „๊ณผ core-js@3๋ฅผ ๊ฐ™์ด ์‚ฌ์šฉํ•ด์•ผ ๋™์ž‘ํ•จ)

๐Ÿš€ frontend/src/main.js





eslint

Ref : eslint

๐ŸŒ”

๐ŸŒ•

์ฐธ๊ณ 

https://marshmello.tistory.com/64
https://marshmello.tistory.com/65?category=1158454
https://medium.com/hivelab-dev/vue-express-mysql-part1-98f68408d444
https://medium.com/hivelab-dev/vue-express-mysql-part2-6d8fc0e497de

profile
protect me from what i want

0๊ฐœ์˜ ๋Œ“๊ธ€