์ ์ง์ ๊ณผ๋ถํ๋ฅผ ๊ด๋ฆฌํ๋ ๊ทผ๋ ฅ ์ด๋ ๊ธฐ๋ก ์น์ฑ
๋๊ทผ
๐ง๐ปโโ
Github(front): https://github.com/protect-me/gm-front
Github(back): https://github.com/protect-me/gm-back
Vue2 + Vuetify + Express + MySQL
(Heroku๋ฅผ ํตํ ๋ฐฐํฌ ์์
์ค)
mkdir gain-muscle
: create gain-muscle
folder
cd gain-muscle
: change directory
gain-muscle
๊ฒฝ๋ก๋ ์ดํroot
๋ก ๋ช ๋ช ํจ.
$ 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
$ 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
$ 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
schema name: gain_muscle
characterset: utf8
collation: utf8_general_ci
(์ ์ฟผ๋ฆฌ ๋ฒํผ - ํ์ด์ง+)
use gain_muscle;
CREATE TABLE users (
userid VARCHAR(255) NOT NULL ,
password VARCHAR(255) NULL ,
name VARCHAR(255) NULL ,
PRIMARY KEY (userid) );
(์ฟผ๋ฆฌ ์คํ ๋ฒํผ - ๋ฒ๊ฐ๋ชจ์)
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
ํ์ด์ง์ ๋์ผํ ํ๋ฉด์ผ๋ก ๋ณ๊ฒฝ ๋ ๊ฒ์ ํ์ธ
root > backend
$ npm install mysql --save
: install mysql
$ npm install bcryptjs --save
: install bcryptjs, ์ํธํ ํด์ ํจ์
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
๊ฐ์ฒด ์ ๋ณด๋ฅผ ์ ํํ๊ฒ ์
๋ ฅํ๋์ง ํ์ธ
axios
๋ฅผ ์ค์นํจ.$ cd frontend
npm install axios --save
$
$ cd ../backend
$ npm install axios --save
root > frontend > src > main.js
(...)
import axios from 'axios'
(...)
Vue.prototype.$http = axios;
(...)
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๋ฅผ ๊ฐ์ด ์ฌ์ฉํด์ผ ๋์ํจ)
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