Add a few more examples
This commit is contained in:
parent
84bcf4c62f
commit
a9ec4fd476
3 changed files with 64 additions and 28 deletions
27
examples/Router.js
Normal file
27
examples/Router.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* Simple demonstration of some router features */
|
||||
|
||||
const port = 9001;
|
||||
|
||||
const app = uWS./*SSL*/App({
|
||||
key_file_name: '/home/alexhultman/key.pem',
|
||||
cert_file_name: '/home/alexhultman/cert.pem',
|
||||
passphrase: '1234'
|
||||
}).get('/user/agent', (res, req) => {
|
||||
/* Read headers */
|
||||
res.end('Your user agent is: ' + req.getHeader('user-agent') + ' thank you, come again!');
|
||||
}).get('/static/yes', (res, req) => {
|
||||
/* Static match */
|
||||
res.end('This is very static');
|
||||
}).get('/candy/:kind', (res, req) => {
|
||||
/* Parameters */
|
||||
res.end('So you want candy? Have some ' + req.getParameter(0) + '!');
|
||||
}).get('/*', (res, req) => {
|
||||
/* Wildcards - make sure to catch them last */
|
||||
res.end('Nothing to see here!');
|
||||
}).listen(port, (token) => {
|
||||
if (token) {
|
||||
console.log('Listening to port ' + port);
|
||||
} else {
|
||||
console.log('Failed to listen to port ' + port);
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue