Skip to content

Instantly share code, notes, and snippets.

@shafiimam
Last active January 5, 2022 08:24
Show Gist options
  • Save shafiimam/f6bc474feab91535841caa040e0946d9 to your computer and use it in GitHub Desktop.
Save shafiimam/f6bc474feab91535841caa040e0946d9 to your computer and use it in GitHub Desktop.
Bypass ngrok tunnel for next js asset files

I have added an assetPrefix: http://localhost:8081 in the next.config file. Due to this the application gets the assets directly from the localhost bypassing the tunnel. Also the hmr reloading happens directly form localhost server.

Only the requests directed to the shopify api go through the tunnel.

const { parsed: localEnv } = require("dotenv").config();
const webpack = require("webpack");
const apiKey = JSON.stringify(process.env.SHOPIFY_API_KEY);
const host = JSON.stringify(process.env.HOST);
module.exports = {
  webpack: (config) => {
    const env = { API_KEY: apiKey, HOST_URL: host };
    config.plugins.push(new webpack.DefinePlugin(env));

    // Add ESM support for .mjs files in webpack 4
    config.module.rules.push({
      test: /\.mjs$/,
      include: /node_modules/,
      type: "javascript/auto",
    });

    return config;
  },
<!--  add this line  -->
  assetPrefix: "http://localhost:8081",
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment