项目作者: Raoul1996

项目描述 :
Reconstruction vote preoject
高级语言: TypeScript
项目地址: git://github.com/Raoul1996/vote-ts-vue.git
创建时间: 2018-06-15T06:20:59Z
项目社区:https://github.com/Raoul1996/vote-ts-vue

开源协议:MIT License

下载


vote-ts-vue

create project by vue-cli version 3, support typescript, pwa and etc

Build Status
CircleCI

English is not my native language, please excuse the typing errors.

第一次尝试使用英语写 Readme,请多包涵

Usage

Install

  1. npm i -g @vue/cli

or by yarn

  1. yarn global add @vue/cli

Run project(front-end)

  1. # clone code repo
  2. git clone https://github.com/Raoul1996/vote-ts-vue.git
  3. # install dependencies
  4. npm i
  5. # serve with hot reload at localhost:8080
  6. npm run serve

more configure see the vue.config.js

Run project(back-end)

it’s a egg.js(node) project, please make sure your node version is 8+,
the database is mysql, please import the seek file in your mysql, and change configuration.
also need to set some variables in your .bashrc or .zshrc, include accessKey(as ak),
secretKey(as sk), github app key(as votepass), qq email pass(as qqpass),

the server also run at https://api.raoul1996.cn

  1. # clone the code repo
  2. git clone https://github.com/Raoul1996/egg-vote.git && cd egg-vote
  3. # install dependencies and dev-dependancies
  4. npm i
  5. # run dev server at 7001 port
  6. npm run dev
  7. # run server at 12012 with daemon mode
  8. npm run start
  9. # stop a runing server which with daemo mode
  10. npm run stop

more information can see egg documents — deployment

Resource

  1. Vue Cli
  2. qshell
  3. codecov

Note

configure tarvis-ci && upload the static resource to CDN

only when some commit push to the master branch, travis will clone the repos and build, then deploy to the server

  • initial repo by travis command tools
  1. # travis login via github email and password
  2. travis login
  3. # inital a travis project
  4. travis init
  5. # encrypt the ssh private key, if you want to scp your file to server
  6. travis encrypt-file ~/.ssh/your_private_key --add
  1. chmod +x qshell
  2. # ak means access key, and sk means secret key
  3. ./qshell account ak sk
  • configure the accessKey and secretKey on travis-ci.org

  • configure the qshell.json for qupload, here is the document

  • set the baseUrl in vue.config.js, which you can get the static resource via this domain form your qiniu bucket

configure coverage on coverage.io

use pug in vue

  • install pug and pug-plain-loader as dev-dependencies
  1. npm i -D pug pug-plain-loader
  • then use pug(jade) in your *.vue file
  1. <template lang="pug">
  2. .login use pug in template tag
  3. el-form(ref="form")
  4. </template>
  5. <script lang="ts"></script>
  6. <style lang="less" scoped></style>

use vuex-class && vue-property-decorator in vue

  • install vuex-class && vue-property-decorator as dependencies
  1. npm i -S vue-class vue-property-decorator
  • then use it in your *.vue file
  1. <template>
  2. <div class="test" @click="handleClk">{{title}}</div>
  3. </template>
  4. <script lang="ts">
  5. import {Component, Vue} from 'vue-property-decorator'
  6. import {Action,Mutation} from 'vuex-class'
  7. // should add the extra-name, to fix the can't resolve problem in unit test
  8. import Captcha from '@/components/captcha.vue'
  9. @Component({
  10. components:{Captcha}
  11. })
  12. export default class Test extends Vue{
  13. // action in vuex
  14. @Action public TestAction!: (data: object) => any
  15. // mutation in vuex
  16. @Mutation public TestMutation!:(data:object) => any
  17. // data
  18. private title: string = 'this is the test component'
  19. // function in methods
  20. private handleClk () {
  21. console.log('your click me')
  22. this.testAction({test:this.test})
  23. this.testMutation({test:this.test})
  24. }
  25. }
  26. </script>
  27. <style lang="less" scoped>
  28. .test{
  29. border: 1px solid #000;
  30. }
  31. </style>

more inof can’t see the login component and captcha component

configure nginx proxy-pass rules to avoid cross origin

Before use typescript and vue reconstruct the vote (login && register) application,
my front-end of the application is deployed on votes.raoul1996.cn,
and the back-end of the application deployed on the api.raoul1996.cn,
so I have to add some extra response headers,
like the Access-Control-Allow-Origin, Access-Controll-Allow-Methods and etc.
more info can read this blog edited by myself three month ago.
now I want to use the nginx to avoid the cross origin statement, only use the proxy-pass and rewrite

About one month ago, I print the nginx configuration file of votes.raoul1996.cn on the vue-vote to show how to configure the ssl_certificate, If you like, you can have a try.

  1. # use regexp to match the rquest which begining with /api/
  2. location ~* ^/api/ {
  3. proxy_set_header X-Url-Scheme $scheme;
  4. proxy_set_header Connection "upgrade";
  5. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  6. proxy_set_header X-Forwarded-For-Forwarded-Proto $https;
  7. proxy_set_header Host $host;
  8. # remove the /api/ preset. eg: /api/captcha/ -> /captcha/
  9. rewrite ^/api/(.*) /$1 break;
  10. # reverse proxy
  11. proxy_pass http://127.0.0.1:12012;
  12. proxy_redirect off;
  13. }

configure circle-ci

add circle-ci for unit-test

  • the document of circle-ci is awesome, just use the default configuration file is enough.
  • use circle-ci version 2
  1. # create the .circleci dir
  2. mkdir .circleci
  3. # create the config.yml
  4. touch config.yml

configure qiniu CDN(It’s just a fun, hhhhh)

Don’t use it. Because it’s very foolish.
because of same-origin policy, google-chrome browser will deny the request with http scheme form the https://votes.raoul1996.cn. On qiniu,only http test domain is free. The developer have to pay for it.
But we can’t use Reverse Proxy via Nginx:

  1. location ~* ^/assets/ {
  2. # Per RFC2616 - 1 year maximum expiry
  3. # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
  4. expires 1y;
  5. access_log off;
  6. log_not_found off;
  7. rewrite ^/assets/(.*) /$1 break;
  8. proxy_pass http://p5j565es2.bkt.clouddn.com;
  9. proxy_redirect off;
  10. }

More info about Forward proxy, Reverse proxy
More info about Nginx rewrite and proxy_pass