Skip to content

Commit

Permalink
静态文件和API使用相对路径
Browse files Browse the repository at this point in the history
  • Loading branch information
ouqiang committed Sep 30, 2018
1 parent 370645f commit ea18109
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ docker run --name gocron -p 5920:5920 -d ouqg/gocron
1. 安装Go1.9+, Node.js, Yarn
2. 安装前端依赖 `make install-vue`
3. 启动gocron, gocron-node `make run`
4. 启动node server `cd web/vue && yarn run dev`, 访问地址 http://localhost:8080
4. 启动node server `make run-vue`, 访问地址 http://localhost:8080

访问http://localhost:8080, API请求会转发给gocron

Expand Down
22 changes: 10 additions & 12 deletions internal/routers/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"
"strconv"

"github.com/go-macaron/binding"
"github.com/go-sql-driver/mysql"
"github.com/lib/pq"
"github.com/go-macaron/binding"
"github.com/ouqiang/gocron/internal/models"
"github.com/ouqiang/gocron/internal/modules/app"
"github.com/ouqiang/gocron/internal/modules/setting"
Expand Down Expand Up @@ -150,21 +150,19 @@ func testDbConnection(form InstallForm) error {
defer db.Close()
err = db.Ping()
if s.Db.Engine == "postgres" && err != nil {
msg := "数据库连接失败"
pgError, _ := err.(*pq.Error)
if pgError.Code == "3D000" {
msg = "数据库不存在"
}
return errors.New(msg)
pgError, ok := err.(*pq.Error)
if ok && pgError.Code == "3D000" {
err = errors.New("数据库不存在")
}
return err
}

if s.Db.Engine == "mysql" && err != nil {
msg := "数据库连接失败"
mysqlError, _ := err.(*mysql.MySQLError)
if mysqlError.Number == 1049 {
msg = "数据库不存在"
mysqlError, ok := err.(*mysql.MySQLError)
if ok && mysqlError.Number == 1049 {
err = errors.New("数据库不存在")
}
return errors.New(msg)
return err
}

return err
Expand Down
3 changes: 2 additions & 1 deletion internal/statik/statik.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ build-vue:
install-vue:
cd web/vue && yarn install

.PHONY: run-vue
run-vue:
cd web/vue && yarn run dev

.PHONY: statik
statik:
go get github.com/rakyll/statik
Expand Down
2 changes: 1 addition & 1 deletion web/vue/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module.exports = {
// Paths
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: '/public/',
assetsPublicPath: 'public/',

/**
* Source Maps
Expand Down
2 changes: 1 addition & 1 deletion web/vue/src/utils/httpClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const AUTH_ERROR_CODE = 401
// 应用未安装
const APP_NOT_INSTALL_CODE = 801

axios.defaults.baseURL = '/api'
axios.defaults.baseURL = 'api'
axios.defaults.timeout = 10000
axios.defaults.responseType = 'json'
axios.interceptors.request.use(config => {
Expand Down

0 comments on commit ea18109

Please sign in to comment.