Storefront
Storefront - a stand-alone deployment of your e-commerce platform front-end. The storefront main goal is to display the data coming from e-commerce platform API. The storefront is not the data-source, rather data-presentation.
Creating a storefront build is simple. It works out-of-the-box with any application created using Create ScandiPWA App. All you need to do is to bundle it using the production build command.
The main challange of deploying ScandiPWA as a storefront is to properly configure the proxy to existing Magento 2 instance. This is automatically done in development, however in production, you must configure it yourself.
To deploy an application to the FREE ScandiPWA static-hosting, you can use ScandiPWA CLI. In order to do it, simply type-in following command from your theme's root:
scandipwa deploy
This will return you a link to your instance and update the
package.json
file with the scandipwa.staticDeploy
field. This field makes you application deployment persistent. Next time you run this command, the changes will be reflected on the same instance.The application will proxy all requests to the Magento server you defined in the
proxy
field of your package.json
.This approach is a little-bit more complex. In order to do it you will need to install the
express
server and http-proxy-middleware
as your theme's dependency. To do it, run:npm i express http-proxy-middleware # for NPM
yarn add express http-proxy-middleware # for Yarn
Then create a new file
server.js
in the application root. Inside, paste following:const express = require('express');
const path = require('path');
const { createProxyMiddleware } = require('http-proxy-middleware');
const app = express();
app.use(express.static(path.join(__dirname, 'build')));
app.use(['/graphql', '/media'], createProxyMiddleware({
target: require('package.json').proxy,
changeOrigin: true
}));
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.listen(9000);
node server.js
The application will proxy all requests to the Magento server you defined in the
proxy
field of your package.json
.