-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
56 lines (51 loc) · 1.44 KB
/
Copy pathserver.js
File metadata and controls
56 lines (51 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const Hapi = require('hapi');
const Inert = require('inert');
const Vision = require('vision');
const Joi = require('joi');
const HapiSwagger = require('hapi-swagger');
const service = require('./service')
const server = new Hapi.Server();
server.connection({
host: 'localhost',
port: 3000
});
const options = {
info: {
'title': 'Test API Documentation',
'version': '0.0.1',
}
};
server.register([
Inert,
Vision,
{
'register': HapiSwagger,
'options': options
}], (err) => {
server.start((err) => {
if (err) {
console.log(err);
} else {
console.log('Server running at:', server.info.uri);
}
server.route({
path: '/institution/{id}/courses',
method: 'GET',
config: {
handler: async (request, reply) => {
const res = await service.getCoursesByInstitutionID();
reply(res.data);
},
description: 'List institutions courses',
notes: 'Pass Institution id ',
tags: ['api'],
validate: {
params: {
id : Joi.number()
.required(),
}
}
}
});
});
});