forked from dwyl/learn-hapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
makemehapi validation using joi object. instructions are bad!
- Loading branch information
Showing
16 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
var Hapi = require('hapi'); | ||
var server = new Hapi.Server(); | ||
|
||
server.connection({ | ||
host: 'localhost', | ||
port: Number(process.argv[2] || 8080) | ||
}); | ||
|
||
function hellohandler(request, reply) { | ||
reply("Hello Hapi"); | ||
} | ||
|
||
server.route({path: '/', method:'GET', handler: hellohandler}); | ||
|
||
server.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
var Hapi = require('hapi'); | ||
var server = new Hapi.Server(); | ||
|
||
server.connection({ | ||
host: 'localhost', | ||
port: Number(process.argv[2] || 8080) | ||
}); | ||
|
||
function routehandler(request, reply) { | ||
reply('Hello ' + encodeURIComponent(request.params.name)); | ||
} | ||
|
||
server.route({path: '/{name*}', method:'GET', handler: routehandler}); | ||
|
||
server.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
var Hapi = require('hapi'); | ||
var server = new Hapi.Server(); | ||
|
||
server.connection({ | ||
host: 'localhost', | ||
port: Number(process.argv[2] || 8080) | ||
}); | ||
|
||
server.route({path: '/{name*}', method:'GET', | ||
handler: { | ||
file: "index.html" | ||
} | ||
}); | ||
|
||
server.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
var Hapi = require('hapi'); | ||
var server = new Hapi.Server(); | ||
|
||
server.connection({ | ||
host: 'localhost', | ||
port: Number(process.argv[2] || 8080) | ||
}); | ||
|
||
function hellohandler(request, reply) { | ||
reply('Hello ' + encodeURIComponent(request.params.name)); | ||
} | ||
|
||
server.route({path: '/{name*}', method:'GET', | ||
handler: { | ||
directory: { path: __dirname } | ||
} | ||
}); | ||
|
||
server.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
var Hapi = require('hapi'); | ||
var Path = require('path'); | ||
var server = new Hapi.Server(); | ||
|
||
server.connection({ | ||
host: 'localhost', | ||
port: Number(process.argv[2] || 8080) | ||
}); | ||
|
||
server.route({path: '/{name*}', method:'GET', | ||
handler: { | ||
view: "index.html" | ||
} | ||
}); | ||
|
||
server.views({ | ||
engines: { | ||
html: require('handlebars') | ||
}, | ||
path: Path.join(__dirname, 'templates') | ||
}); | ||
|
||
server.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var Hapi = require('hapi'); | ||
var server = new Hapi.Server(); | ||
|
||
server.connection({ | ||
host: 'localhost', | ||
port: Number(process.argv[2] || 8080) | ||
}); | ||
|
||
server.route({path: '/proxy', method:'GET', | ||
handler: { | ||
proxy: { | ||
host: '127.0.0.1', | ||
port: 65535 | ||
} | ||
} | ||
}); | ||
|
||
server.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var Hapi = require('hapi'); | ||
var Path = require('path'); | ||
var server = new Hapi.Server(); | ||
|
||
server.connection({ | ||
host: 'localhost', | ||
port: Number(process.argv[2] || 8080) | ||
}); | ||
|
||
server.route({path: '/', method:'GET', | ||
handler: { | ||
view: "helper-index.html" | ||
} | ||
}); | ||
|
||
server.views({ | ||
engines: { | ||
html: require('handlebars') | ||
}, | ||
path: Path.join(__dirname, 'templates'), | ||
helpersPath: Path.join(__dirname, 'helpers') | ||
}); | ||
|
||
server.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var Fs = require('fs'); | ||
var Hapi = require('hapi'); | ||
var Path = require('path'); | ||
var Rot13 = require('rot13-transform'); | ||
|
||
var server = new Hapi.Server(); | ||
|
||
server.connection({ | ||
host: 'localhost', | ||
port: Number(process.argv[2] || 8080) | ||
}); | ||
|
||
server.route({ | ||
method: 'GET', | ||
path: '/', | ||
config: { | ||
handler: function (request, reply) { | ||
var thisfile = Fs.createReadStream(Path.join(__dirname, 'input.txt')); | ||
reply(thisfile.pipe(Rot13())); | ||
} | ||
} | ||
}); | ||
|
||
server.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var Hapi = require('hapi'); | ||
var Joi = require('joi'); | ||
var server = new Hapi.Server(); | ||
|
||
server.connection({ | ||
host: 'localhost', | ||
port: Number(process.argv[2] || 8080) | ||
}); | ||
|
||
function myHandler(request, reply) { | ||
reply('Hello Joi!'); | ||
} | ||
|
||
var routeConfig = { | ||
path: '/a/path/{with}/{parameters}', | ||
method: 'GET', | ||
handler: myHandler, | ||
config: { | ||
validate: { | ||
params: { | ||
with: Joi.string().required(), | ||
parameters: Joi.string().required() | ||
} | ||
} | ||
} | ||
} | ||
|
||
server.route(routeConfig); | ||
|
||
server.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
var Hapi = require('hapi'); | ||
var Joi = require('joi'); | ||
var server = new Hapi.Server(); | ||
|
||
server.connection({ | ||
host: 'localhost', | ||
port: Number(process.argv[2] || 8080) | ||
}); | ||
|
||
function myHandler(request, reply) { | ||
reply('login successful'); | ||
} | ||
|
||
var routeConfig = { | ||
path: '/login', | ||
method: 'POST', | ||
config: { | ||
handler: myHandler, | ||
validate: { | ||
payload: Joi.object({ | ||
username: Joi.string(), | ||
password: Joi.string().alphanum(), | ||
accessToken: Joi.string().alphanum(), | ||
birthyear: Joi.number().integer().min(1900).max(2013), | ||
email: Joi.string().email() | ||
}) | ||
.options({allowUnknown: true}) | ||
// .with('username', 'birthyear') | ||
.without('password', 'accessToken') | ||
} | ||
} | ||
} | ||
|
||
server.route(routeConfig); | ||
|
||
server.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<html> | ||
<head><title>Hello Directories</title></head> | ||
<body> | ||
Hello Directories | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = function(context) { | ||
var query = context.data.root.query; | ||
return query.name + query.suffix; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<html> | ||
<head><title>Hello Handling</title></head> | ||
<body> | ||
Hello Handling | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The Pursuit of Hapi-ness |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<html> | ||
<head><title>Hello {{helper}}</title></head> | ||
<body> | ||
Hello {{helper}} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<html> | ||
<head><title>Hello {{query.name}}</title></head> | ||
<body> | ||
Hello {{query.name}} | ||
</body> | ||
</html> |