Skip to content

Commit f725498

Browse files
committed
example
1 parent 861ec24 commit f725498

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

README.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ Example configuration for hapi-swaggered + hapi-swaggered-ui
6363
```js
6464
const Hapi = require('hapi');
6565

66-
const server = Hapi.Server({ port: 8000 });
67-
6866
(async () => {
67+
const server = await new Hapi.Server({
68+
port: 8000
69+
})
70+
6971
await server.register([
7072
require('inert'),
7173
require('vision'),
@@ -99,22 +101,23 @@ const server = Hapi.Server({ port: 8000 });
99101
}
100102
}
101103
}
102-
]);
103-
})();
104-
105-
server.route({
106-
path: '/',
107-
method: 'GET',
108-
handler (request, h) {
109-
h.response().redirect('/docs');
110-
}
111-
});
104+
])
112105

113-
(async () => {
114-
await server.start();
115-
console.log('started on http://localhost:8000')
106+
server.route({
107+
path: '/',
108+
method: 'GET',
109+
handler (request, h) {
110+
return h.response().redirect('/docs')
111+
}
112+
})
116113

117-
})();
114+
try {
115+
await server.start()
116+
console.log('Server running at:', server.info.uri)
117+
} catch (err) {
118+
console.log(err)
119+
}
120+
})()
118121
```
119122

120123
Demo Routes

0 commit comments

Comments
 (0)