vuestorefront / vue-storefront

Alokai is a Frontend as a Service solution that simplifies composable commerce. It connects all the technologies needed to build and deploy fast & scalable ecommerce frontends. It guides merchants to deliver exceptional customer experiences quickly and easily.
https://www.alokai.com
MIT License
10.64k stars 2.08k forks source link

feat: configuration options in create server #7104

Closed jagoral closed 7 months ago

jagoral commented 7 months ago

๐Ÿ”— Linked issue

โ“ Type of change

๐Ÿ“š Description

Context: The change is related to the hacky cors config customization which we've got atm in templates. Currently, the middleware app is run mostly on port 4000, because Storefront app occupies port 3000 (default port for Next.js), so I could change the origin to accept also localhost:4000, however there are also multistores which are run locally and other cases, when the current cors config is enough. The workaround which we do in the templates looks as follows

  const CORS_MIDDLEWARE_NAME = "corsMiddleware";

  const corsMiddleware = app._router.stack.find(
    (middleware: any) => middleware.name === CORS_MIDDLEWARE_NAME,
  );
  const multistoreUrls = listOfStoresDomains.map((storeUrl) => `https://${storeUrl}`);
  corsMiddleware.handle = cors({
    origin: [
      "https://dev.local",
      "http://localhost:3000",
      "http://localhost:3333",
      ...multistoreUrls,
    ],
    optionsSuccessStatus: 200,
    credentials: true,
  });

I propose to instead by default allow cors for all origins, and pass an option to configure it when calling createServer.

I've added also an option to pass config for cookieParser, and bodyParser, but I'm open to exclude it from this PR, because it extends our API layer.

๐Ÿ“ Checklist

changeset-bot[bot] commented 7 months ago

๐Ÿฆ‹ Changeset detected

Latest commit: 46e77765796df4d56d9d6fc535e72da131b54213

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages | Name | Type | | -------------------------- | ----- | | @vue-storefront/middleware | Minor | | @vue-storefront/multistore | Major |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR