2019-01-17 06:22:31 +00:00
|
|
|
/* Simple demonstration of some router features */
|
|
|
|
|
2019-01-17 06:26:25 +00:00
|
|
|
const uWS = require('../dist/uws.js');
|
2019-01-17 06:22:31 +00:00
|
|
|
const port = 9001;
|
|
|
|
|
|
|
|
const app = uWS./*SSL*/App({
|
2019-01-17 10:42:53 +00:00
|
|
|
key_file_name: 'misc/key.pem',
|
|
|
|
cert_file_name: 'misc/cert.pem',
|
2019-01-17 06:22:31 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|