Skip to content

Latest commit

 

History

History
89 lines (63 loc) · 1.92 KB

README.md

File metadata and controls

89 lines (63 loc) · 1.92 KB

Adonis Nextjs 🚀

A provider to initialize nextjs app with adonis.

npm

Installation

You can install the package from npm.

this provider assume you have nextjs, React & React Dom

adonis install adonis-nextjs

Configure

Register provider

The provider must be registered as a provider.

const providers = [...,'adonis-nextjs/providers/NextProvider'];

Register your routes

const Route = use('Route');
const Next = use('Adonis/Addons/Next');
const handler = Next.getRequestHandler();

// API Endpoint for your database
Route.get('/api', ({ request }) => {
	return { greeting: "I'm Api Endpoint" };
});

// * Next Routes
Route.get('/b', ({ request, response }) => {
	const query = request.get();
	return Next.render(request.request, response.response, '/b', query);
});

Route.get('/post/:id', ({ request, response, params }) =>
	Next.render(request.request, response.response, '/b', {
		id: params.id
	})
);

Route.get(
	'*',
	({ request, response }) =>
		new Promise((resolve, reject) => {
			handler(request.request, response.response, promise => {
				promise.then(resolve).catch(reject);
			});
		})
);

Adding next.js folder

The next project directory is next by default, but you can change it using environment variables NEXT_FOLDER.

Register next.js Commands

{
	"scripts": {
		"dev": "node server.js",
		"build": "next build ./next",
		"export": "next export ./next",
		"start": "NODE_ENV=production node server.js"
	}
}

Release History

Checkout CHANGELOG.md file for release history.

Meta

@AdonisJs

@nextjs

Checkout LICENSE for license information.