0.4.2 • Published 1 year ago

@monteway/next v0.4.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@monteway/next

Useful utilities for Next.js apps.\ Also a production-ready Dockerfile for Next.js projects.

Install

npm i @moneway/next

Usage

errorPropsResponse

Return an object that is compatible with the result of getServerSideProps / getStaticProps and includes an internal property marking the response as having some error.

import { errorPropsResponse } from '@monteway/next/error';
import type { GetServerSidePropsContext } from 'next';

export async function getServerSideProps(context: GetServerSidePropsContext) {
  try {
    // Pretend we have a call here to some API that can throw
    // an error when user has no access to the page.
  } catch {
    // This responds with HTTP 403 status
    // and returns
    //  {
    //    props: {
    //      error: 'You cannot access this page',
    //      __isErrorProps__: true
    //    },
    //  }
    return errorPropsResponse(context.res, {
      statusCode: 403,
      error: 'You cannot access this page',
    });
  }
}

isErrorProps

Checks if the argument is from errorPropsResponse.

import { errorPropsResponse, isErrorProps } from '@monteway/next/error';

const response = errorPropsResponse(null, {
  statusCode: 403,
  error: 'You cannot access this page',
});

isErrorProps(response.props);
// true

Docker

This package includes also a official Dockerfile for Next.js project which is production ready.\ We have extended it with some optional build arguments that can be used to extend the image.

--build-argDescription
BEFORE_INSTALL_COMMANDRun before npm install
AFTER_INSTALL_COMMANDRun after npm install
BEFORE_BUILD_COMMANDRun before npm run build
AFTER_BUILD_COMMANDRun after npm run build

Example usage of the Dockerfile (make sure the Docker context is root of the Next.js app):

docker build \
  --build-arg BEFORE_INSTALL_COMMAND="exit 0" \
  --build-arg AFTER_INSTALL_COMMAND="exit 0" \
  --build-arg BEFORE_BUILD_COMMAND="exit 0" \
  --build-arg AFTER_BUILD_COMMAND="exit 0" \
  --tag ${IMAGE_TAG} \
  --file node_modules/@monteway/next/dockerfile .
0.4.1-rc.1

1 year ago

0.4.0-rc.2

1 year ago

0.4.0-rc.1

1 year ago

0.3.2-rc.1

1 year ago

0.4.1

1 year ago

0.3.2

1 year ago

0.4.0

1 year ago

0.4.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.3.0-rc.1

1 year ago

0.2.0

1 year ago

0.2.0-rc.6

1 year ago

0.2.0-rc.5

1 year ago

0.2.0-rc.4

1 year ago

0.2.0-rc.3

1 year ago

0.2.0-rc.2

1 year ago

0.2.0-rc.1

1 year ago

0.1.0

1 year ago

0.0.40-rc.9

1 year ago

0.0.40-rc.8

1 year ago

0.0.40-rc.7

1 year ago

0.0.40-rc.6

1 year ago

0.0.40-rc.5

1 year ago

0.0.40-rc.4

1 year ago

0.0.40-rc.3

1 year ago

0.0.40-rc.2

1 year ago