Skip to content

Commit b8efbd0

Browse files
dloedadloeda
authored andcommitted
📄 chore: Clean unused code
1 parent 4d83d70 commit b8efbd0

File tree

3 files changed

+2
-84
lines changed

3 files changed

+2
-84
lines changed

‎config/routes.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"^$": "../config/info.json",
2+
"^/$": "../config/info.json",
33
"cached": "cached.json",
44
".*logs/{{param1}}/{{param2}}": "user/default.js"
55
}

‎libs/finder.js‎

Lines changed: 1 addition & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function findMock(config, req) {
4848
params,
4949
query,
5050
type,
51-
error: mockPath ? false : constants['error.not-found']
51+
error: mockPath.path ? false : constants['error.not-found']
5252
};
5353
}
5454

@@ -91,73 +91,6 @@ function findMockPath(filePath, req, config) {
9191
}
9292
}
9393

94-
function findFile(config, req) {
95-
var filePath,
96-
defaultFilePath,
97-
error = false,
98-
method = '.' + (req.method || '').toLowerCase(),
99-
path,
100-
type;
101-
102-
if (req.params) {
103-
filePath = config.mocks + '/' + req.params[0];
104-
} else {
105-
filePath = config['conf-folder'] + config['info-file'];
106-
}
107-
defaultFilePath = filePath.substr(0, filePath.lastIndexOf('/')) + '/' + constants['file.name.default'];
108-
109-
if (fs.existsSync(filePath + method + constants['file.ext:code'])) {
110-
path = filePath + method + constants['file.ext:code'];
111-
type = constants['content.code'];
112-
} else if (fs.existsSync(filePath + method + constants['file.ext:data'])) {
113-
path = filePath + method + constants['file.ext:data'];
114-
type = constants['content.data'];
115-
} else if (fs.existsSync(filePath + constants['file.ext:code'])) {
116-
path = filePath + constants['file.ext:code'];
117-
type = constants['content.code'];
118-
} else if (fs.existsSync(filePath + constants['file.ext:data'])) {
119-
path = filePath + constants['file.ext:data'];
120-
type = constants['content.data'];
121-
} else if (fs.existsSync(defaultFilePath + method + constants['file.ext:code'])) {
122-
path = defaultFilePath + method + constants['file.ext:code'];
123-
type = constants['content.code'];
124-
} else if (fs.existsSync(defaultFilePath + method + constants['file.ext:data'])) {
125-
path = defaultFilePath + method + constants['file.ext:data'];
126-
type = constants['content.data'];
127-
} else if (fs.existsSync(defaultFilePath + constants['file.ext:code'])) {
128-
path = defaultFilePath + constants['file.ext:code'];
129-
type = constants['content.code'];
130-
} else if (fs.existsSync(defaultFilePath + constants['file.ext:data'])) {
131-
path = defaultFilePath + constants['file.ext:data'];
132-
type = constants['content.data'];
133-
} else {
134-
error = constants['error.not-found'];
135-
}
136-
137-
return {
138-
error: error,
139-
path: path,
140-
type: type
141-
};
142-
}
143-
144-
function openFile(config, req) {
145-
let fileInfo = findFile(config, req);
146-
147-
if (fileInfo.error) return fileInfo;
148-
149-
fileInfo.content = fs.readFileSync(fileInfo.path);
150-
if (fileInfo.type === constants['content.code']) {
151-
fileInfo.context = {
152-
req: req,
153-
params: req.params,
154-
query: req.query,
155-
mock: false
156-
};
157-
}
158-
return fileInfo;
159-
}
160-
16194
function openMock(config, req) {
16295
let fileInfo = findMock(config, req);
16396

@@ -193,23 +126,12 @@ function parseFile(file) {
193126
return JSON.parse(JSON.stringify(response));
194127
}
195128

196-
function getFile(config, req) {
197-
return parseFile(openFile(config, req));
198-
}
199129

200130
function getMock(config, req) {
201131
return parseFile(openMock(config, req));
202132
}
203133

204-
function getInfo(config) {
205-
return getFile(config, {
206-
path: (config['conf-folder'] + config['info-file'])
207-
});
208-
}
209-
210134
// Exports
211135
module.exports = {
212-
getFile,
213-
getInfo,
214136
getMock
215137
};

‎server.js‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ app.use((req, res, next) => {
2929
next()
3030
})
3131

32-
app.all('/', (_, res) =>
33-
utils.fillResponse(res,
34-
finder.getInfo(config)));
35-
3632
app.all('/**', (req, res, next) =>
3733
next(utils.fillResponse(res,
3834
finder.getMock(config, req))))

0 commit comments

Comments
 (0)