A
Alokaiβ€’12mo ago
jeanpier92

Cors Policy

Please, does anyone know how to configure the cors policy in vuestorefront?
No description
9 Replies
rohrig
rohrigβ€’12mo ago
Hi @jeanpier92 πŸ‘‹ , here's an example
import { createServer } from "@vue-storefront/middleware";
import { integrations } from "./middleware.config.js";
import cors from "cors";
import consola from "consola";

(async () => {
const CORS_MIDDLEWARE_NAME = "corsMiddleware";
const app = await createServer({ integrations });

const corsMiddleware = app._router.stack.find(
(middleware) => middleware.name === CORS_MIDDLEWARE_NAME
);

corsMiddleware.handle = cors({
origin: ["http://localhost:3000"],
credentials: true,
});

const port = Number(process.argv[3]) || 8181;

app.listen(port, 'localhost', () => {
consola.success(`API server listening on http://localhost:${port}`);
});
})();
import { createServer } from "@vue-storefront/middleware";
import { integrations } from "./middleware.config.js";
import cors from "cors";
import consola from "consola";

(async () => {
const CORS_MIDDLEWARE_NAME = "corsMiddleware";
const app = await createServer({ integrations });

const corsMiddleware = app._router.stack.find(
(middleware) => middleware.name === CORS_MIDDLEWARE_NAME
);

corsMiddleware.handle = cors({
origin: ["http://localhost:3000"],
credentials: true,
});

const port = Number(process.argv[3]) || 8181;

app.listen(port, 'localhost', () => {
consola.success(`API server listening on http://localhost:${port}`);
});
})();
jeanpier92
jeanpier92β€’12mo ago
hello! thanks for your answer! I took your example but I get the same result 😦
rohrig
rohrigβ€’12mo ago
I see you have magentotovue.test as your url. Did you also change this in the .env file?
No description
rohrig
rohrigβ€’12mo ago
typically they are magento.test by default.
No description
rohrig
rohrigβ€’12mo ago
So you'll need to change that as well.
jeanpier92
jeanpier92β€’12mo ago
Actually what I want to do is the vuestorefront instance with multiple stores so I configured magentovue.test in nginx as a proxy where I redirect it to http://localhost:3000. Here I am racking my brain to configure this. Do you know how to do it so you can guide me please?
No description
rohrig
rohrigβ€’12mo ago
I see. Did you try adding the magentotovue.test to the origin array?
No description
jeanpier92
jeanpier92β€’12mo ago
That's right my friend. I added it to the origin array
rohrig
rohrigβ€’12mo ago
Great πŸ˜„
Want results from more Discord servers?
Add your server