Skip to content

Commit

Permalink
Super admin cors + Cookie issue fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
shlok-manojkumar committed Oct 13, 2022
1 parent b9c3371 commit ec097ef
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 8 deletions.
7 changes: 6 additions & 1 deletion backend/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,24 @@ export default (rootDirectory) => {

let product = require("./routes/product")
let dashboard = require("./routes/dashboard")
let store = require("./routes/store");

const { configModule } = getConfigFile(rootDirectory, "medusa-config")

const { projectConfig } = configModule
const corsOptions = {
origin: projectConfig.store_cors.split(","),
origin: [...projectConfig.store_cors.split(","), projectConfig.admin_cors.split(",")],
credentials: true,
}



router.use("/sales-details/:duration", cors(corsOptions))
router.use("/admin/stores", cors(corsOptions))

// localhost:3000/sales-details?duration=week
router.get("/sales-details/:duration", middlewares.wrap(dashboard.getSalesDetails))
router.get("/admin/stores", middlewares.wrap(store.getAllStores))

return router
}
8 changes: 7 additions & 1 deletion backend/src/api/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ export default () => {

let product = require("./routes/product")
let dashboard = require("./routes/dashboard")
let store = require('./')

const storeCors = config.store_cors || ""
const storeCors = config.store_cors || "" + "," + config.admin_cors || ""

router.use(
cors({
Expand All @@ -26,6 +27,11 @@ export default () => {
"/sales-details",
bodyParser.json(),
middlewares.wrap(dashboard.getSalesDetails))

router.post(
"/sales-details",
bodyParser.json(),
middlewares.wrap(dashboard.getSalesDetails))

// router.post(
// "/admin/update-product",
Expand Down
21 changes: 21 additions & 0 deletions backend/src/api/routes/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export async function getAllStores(req, res) {

try {
const storeService = req.scope.resolve("storeService")

let stores = await getStores(storeService);

res.json({stores});


} catch (err) {
throw err
}
}

async function getStores(storeService) {
const manager = storeService.manager_;
const storeRepo = manager.getCustomRepository(storeService.storeRepository_);

return await storeRepo.find({});;
}
5 changes: 3 additions & 2 deletions super-admin/src/services/configs/urlConfigs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const URLConfigs = {
BASE_URL: 'http://localhost:3000/api/',
GET_Work_Package_URL: 'getWorkPackages'
BASE_URL: 'http://localhost:3000/',
GET_STORES: 'admin/stores',
ADMIN_AUTH: 'admin/auth'
};

export default URLConfigs;
4 changes: 2 additions & 2 deletions super-admin/src/services/endpointConfigs.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import axios from 'axios';

export const get = async ({ url, headers, data }) => {
return await axios.get(url, { params: data, headers: headers });
return await axios.get(url, { headers: headers, withCredentials: true, json: true,maxContentLength: 900 });
};

export const post = async ({ url, headers, data }) => {
return await axios.post(url, data, { ...headers });
return await axios.post(url, data, { headers: headers, withCredentials: true, json: true,maxContentLength: 900 });
};

export const put = async ({ url, headers, data }) => {
Expand Down
2 changes: 1 addition & 1 deletion super-admin/src/services/planner/plannerAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { dispatch } from '../dispatcher';
const loadPost = async () => {
var values = await loadPostService();
console.log(values);
dispatch({ type: actionTypes.GET_WORK_PACKAGE_DATA, data: values.data });
// dispatch({ type: actionTypes.GET_WORK_PACKAGE_DATA, data: values.data });
};

const adminAuth = async ({ email, password }) => {
Expand Down
2 changes: 1 addition & 1 deletion super-admin/src/services/planner/plannerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const saveData = async (data) => {

export const loadPostService = async () => {
const response = await get({
url: URLConfigs.BASE_URL + URLConfigs.GET_STORE,
url: URLConfigs.BASE_URL + URLConfigs.GET_STORES,
});

return response;
Expand Down

0 comments on commit ec097ef

Please sign in to comment.