File tree 1 file changed +53
-43
lines changed
1 file changed +53
-43
lines changed Original file line number Diff line number Diff line change 40
40
41
41
``` javascript
42
42
43
- var gulp = require (' gulp' );
43
+ var gulp = require (' gulp' )
44
44
45
- var connect = require (' gulp-connect' );
45
+ var connect = require (' gulp-connect' )
46
46
47
- var webserver = require (' gulp-webserver' );
47
+ var webserver = require (' gulp-webserver' )
48
48
49
49
var urlTool = require (' url' )
50
50
51
51
var qs = require (' qs' )
52
52
53
+ var fs = require (' fs' )
53
54
54
- var dataBase = {
55
- users: [
56
- {
57
- name: ' zhangsan' ,
58
- password: 123456
59
- },
60
- {
61
- name: ' lisi' ,
62
- password: 123456
63
- },
64
- ],
65
- goodslist: [
66
- {
67
- name: ' page1' ,
68
- data: [
69
- {
70
- name: ' 商品1' ,
71
- price: .1
72
- },
73
- {
74
- name: ' 商品2' ,
75
- price: .2
76
- }
77
- ]
78
- },
79
- {
80
- name: ' page2' ,
81
- data: [
82
- {
83
- name: ' 商品3' ,
84
- price: .3
85
- },
86
- {
87
- name: ' 商品4' ,
88
- price: .4
89
- }
90
- ]
91
- }
92
- ],
93
- home: ' <html><meta charset="utf-8"; /> <style> div{background:red}</style> <div>这是首页</div></html>'
55
+ var hasDataBase = fs .existsSync (' ./dataBase.json' )
56
+
57
+ var dataBase = {}
94
58
59
+ if (hasDataBase){
60
+ dataBase = JSON .parse (fs .readFileSync (' ./dataBase.json' ).toString ())
61
+ }else {
62
+ dataBase = {
63
+ users: [
64
+ {
65
+ name: ' zhangsan' ,
66
+ password: 123456
67
+ },
68
+ {
69
+ name: ' lisi' ,
70
+ password: 123456
71
+ },
72
+ ],
73
+ goodslist: [
74
+ {
75
+ name: ' page1' ,
76
+ data: [
77
+ {
78
+ name: ' 商品1' ,
79
+ price: .1
80
+ },
81
+ {
82
+ name: ' 商品2' ,
83
+ price: .2
84
+ }
85
+ ]
86
+ },
87
+ {
88
+ name: ' page2' ,
89
+ data: [
90
+ {
91
+ name: ' 商品3' ,
92
+ price: .3
93
+ },
94
+ {
95
+ name: ' 商品4' ,
96
+ price: .4
97
+ }
98
+ ]
99
+ }
100
+ ],
101
+ home: ' <html><meta charset="utf-8"; /> <style> div{background:red}</style> <div>这是首页</div></html>'
102
+ }
95
103
}
96
104
97
105
98
106
107
+
108
+
99
109
function login (userName ,password ){
100
110
101
111
var exist = false ;
You can’t perform that action at this time.
0 commit comments