rsnext/examples/custom-server-hapi/server.js
Eduardo P. Rivero 2259a7ec1f Updating hapijs package name (#7664)
* Updating hapijs package name

Hapi was moved to a new module under the name @hapijs/hapi.

Right now installing just as hapi is giving you this warning:

```bash
npm WARN deprecated hapi@18.1.0: This module has moved and is now available at @hapi/hapi. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
```
This change does not affect the integration with next and it continues to work great.

* Update package.json
2019-06-26 09:40:35 +02:00

54 lines
1.1 KiB
JavaScript

const next = require('next')
const Hapi = require('@hapi/hapi')
const {
pathWrapper,
defaultHandlerWrapper,
nextHandlerWrapper
} = require('./next-wrapper')
const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const server = new Hapi.Server({
port
})
app.prepare().then(async () => {
server.route({
method: 'GET',
path: '/a',
handler: pathWrapper(app, '/a')
})
server.route({
method: 'GET',
path: '/b',
handler: pathWrapper(app, '/b')
})
server.route({
method: 'GET',
path: '/_next/{p*}' /* next specific routes */,
handler: nextHandlerWrapper(app)
})
server.route({
method: 'GET',
path: '/static/{p*}' /* use next to handle static files */,
handler: nextHandlerWrapper(app)
})
server.route({
method: 'GET',
path: '/{p*}' /* catch all route */,
handler: defaultHandlerWrapper(app)
})
try {
await server.start()
console.log(`> Ready on http://localhost:${port}`)
} catch (error) {
console.log('Error starting server')
console.log(error)
}
})