NX is a tool for managing monorepos.

This guide shows you how to create a connector for your NX application on Layer0. Here we use Next.js for the default NX project.

In the root of your nx monorepo, run:

npm i -g @layer0/cli
0 init

Since our Next.js app isn't located in the root of the project as the @layer0/next connector expects, we'll need to define our own custom connector. To do so:

  1. Set connector: './layer0' in layer0.config.js
  2. Copy the layer0 directory from the example into the root of your monorepo.

const { Router } = require('@layer0/core/router')
const { default: NextRoutes } = require('@layer0/next/router/NextRoutes')

module.exports = new Router()
  .match('/service-worker.js', ({ serviceWorker }) => {
    return serviceWorker('.next/static/service-worker.js')
  .use(new NextRoutes('apps/next-app')) // provide the path to your Next.js app relative to the root of the monorepo here

To run your Next.js app in development mode behind Layer0, run:

0 dev

To deploy your app to Layer0, run:

0 deploy
Edit this guide on GitHub