-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.js
31 lines (27 loc) · 955 Bytes
/
routes.js
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
var Joi = require('joi');
var Inert = require('inert');
module.exports = function(server) {
server.register(Inert, function () {});
server.route({
method: 'GET',
path: '/{url?}',
handler: function (request, reply) {
var url = request.params.url ? encodeURIComponent(request.params.url) : 'index.html';
if (url == 'index.html'){
reply.file('public/index.html');
} else if (url == 'bundle.js') {
reply.file('public/bundle.js');
} else if (url == 'favicon.ico') {
reply.file('public/favicon.ico');
} else {
server.methods.translateUrl(url, function(err, long_url) {
if (err) {
reply(err).code(404);
} else {
reply.redirect(long_url);
}
})
}
}
});
};