A provider to initialize nextjs app with adonis.
You can install the package from npm.
this provider assume you have nextjs, React & React Dom
adonis install adonis-nextjs
The provider must be registered as a provider
.
const providers = [...,'adonis-nextjs/providers/NextProvider'];
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);
});
})
);
The next project directory is next
by default, but you can change it using environment variables NEXT_FOLDER
.
{
"scripts": {
"dev": "node server.js",
"build": "next build ./next",
"export": "next export ./next",
"start": "NODE_ENV=production node server.js"
}
}
Checkout CHANGELOG.md file for release history.
Checkout LICENSE for license information.