Skip to content

Commit 9ba6c82

Browse files
authored
feat(mockServer): mockserver support custom database path (opentiny#1501)
* fix: remove useless data and fix pagename * feat: mockserver support custom dbpath
1 parent f473753 commit 9ba6c82

File tree

6 files changed

+20
-16
lines changed

6 files changed

+20
-16
lines changed

mockServer/src/database/pages.db

Lines changed: 1 addition & 4 deletions
Large diffs are not rendered by default.

mockServer/src/services/block.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
1010
*
1111
*/
12-
import path from 'path'
1312
import DateStore from '@seald-io/nedb'
14-
import { getResponseData } from '../tool/Common'
13+
import { getDatabasePath, getResponseData } from '../tool/Common'
14+
1515
export default class BlockService {
1616
constructor() {
1717
this.db = new DateStore({
18-
filename: path.resolve(__dirname, '../database/blocks.db'),
18+
filename: getDatabasePath('blocks.db'),
1919
autoload: true
2020
})
2121

mockServer/src/services/blockCategory.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
1010
*
1111
*/
12-
import path from 'path'
1312
import DateStore from '@seald-io/nedb'
14-
import { getResponseData } from '../tool/Common'
13+
import { getDatabasePath, getResponseData } from '../tool/Common'
1514
import appinfo from '../assets/json/appinfo.json'
15+
1616
export default class BlockCategoryService {
1717
constructor() {
1818
this.db = new DateStore({
19-
filename: path.resolve(__dirname, '../database/blockCategories.db'),
19+
filename: getDatabasePath('blockCategories.db'),
2020
autoload: true
2121
})
2222

mockServer/src/services/blockGroup.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
1010
*
1111
*/
12-
import path from 'path'
1312
import DateStore from '@seald-io/nedb'
14-
import { getResponseData } from '../tool/Common'
13+
import { getDatabasePath, getResponseData } from '../tool/Common'
1514
import appinfo from '../assets/json/appinfo.json'
15+
1616
export default class BlockGroupService {
1717
constructor() {
1818
this.db = new DateStore({
19-
filename: path.resolve(__dirname, '../database/blockGroups.db'),
19+
filename: getDatabasePath('blockGroups.db'),
2020
autoload: true
2121
})
2222

mockServer/src/services/pages.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010
*
1111
*/
1212

13-
import path from 'path'
1413
import DateStore from '@seald-io/nedb'
15-
import { getResponseData } from '../tool/Common'
14+
import { getDatabasePath, getResponseData } from '../tool/Common'
1615

1716
export default class PageService {
1817
constructor() {
1918
this.db = new DateStore({
20-
filename: path.resolve(__dirname, '../database/pages.db'),
19+
filename: getDatabasePath('pages.db'),
2120
autoload: true
2221
})
2322

mockServer/src/tool/Common.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
*
1111
*/
1212

13+
import path from 'path'
14+
1315
// 截取字符串,多余的部分用...代替
1416
export const setString = (str, len) => {
1517
let StrLen = 0
@@ -72,3 +74,9 @@ export const getResponseData = (data, error) => {
7274
}
7375
return res
7476
}
77+
78+
// 获取数据库路径
79+
export const getDatabasePath = (fileName) => {
80+
const databasePath = process.env.DATABASE_PATH || path.resolve(__dirname, '../database')
81+
return path.resolve(databasePath, fileName)
82+
}

0 commit comments

Comments
 (0)