Fixed mock-api to accept POST requests
This commit is contained in:
@@ -82,6 +82,7 @@ const apiData = {
|
||||
currentUser: currentUser.generate(),
|
||||
authorizations: authorizations.generate(),
|
||||
getTokenFullAccess: authTokens.auth_code_from_CIAM_with_all_permissions,
|
||||
invites: [],
|
||||
};
|
||||
|
||||
fs.writeFileSync('api.json', JSON.stringify(apiData, null, '\t'));
|
||||
|
||||
@@ -30,20 +30,24 @@ server.use(
|
||||
);
|
||||
|
||||
router.render = (req, res) => {
|
||||
const pathname = req._parsedOriginalUrl.pathname;
|
||||
const method = req.originalMethod;
|
||||
const parsedUrl = method === 'GET' ? req._parsedOriginalUrl : req._parsedUrl;
|
||||
const pathname = parsedUrl.pathname;
|
||||
const params = parsedUrl.query ? new URLSearchParams(parsedUrl.query) : null;
|
||||
const requestHeaders = req.headers;
|
||||
|
||||
// all paths except /auth/token requires Authorization header.
|
||||
if (!pathname.includes('/auth/token') && !req.headers.authorization) {
|
||||
if (!pathname.includes('/auth/token') && !requestHeaders.authorization) {
|
||||
return res.status(401).jsonp({ error: 'No valid access-token' });
|
||||
}
|
||||
|
||||
// Return custom error when status is 404.
|
||||
if (res.statusCode === 404) {
|
||||
return res.status(404).jsonp({ error: `Can't find path: ${pathname}` });
|
||||
}
|
||||
|
||||
const params = req._parsedUrl.query ? new URLSearchParams(req._parsedUrl.query) : null;
|
||||
|
||||
// Add createdAt to the body
|
||||
if (req.originalMethod === 'POST') {
|
||||
if (method === 'POST') {
|
||||
req.body.createdAt = Date.now();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user