Wrap req.getQuery, req.getMethod, res.close, res.onData & add Upload example
This commit is contained in:
parent
3558bf30d9
commit
4ae2facba7
5 changed files with 83 additions and 3 deletions
36
examples/Upload.js
Normal file
36
examples/Upload.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
/* Minimal POST example a SSL/non-SSL */
|
||||
/* todo: proper throttling, better example */
|
||||
|
||||
/* a good example would be using the router to get
|
||||
* a file name and stream that file to disk */
|
||||
|
||||
const uWS = require('../dist/uws.js');
|
||||
const port = 9001;
|
||||
|
||||
const app = uWS./*SSL*/App({
|
||||
key_file_name: '/home/alexhultman/key.pem',
|
||||
cert_file_name: '/home/alexhultman/cert.pem',
|
||||
passphrase: '1234'
|
||||
}).post('/*', (res, req) => {
|
||||
console.log('Posted to ' + req.getUrl());
|
||||
res.onData((chunk, isLast) => {
|
||||
/* Buffer this anywhere you want to */
|
||||
console.log('Got chunk of data with length ' + chunk.byteLength + ', isLast: ' + isLast);
|
||||
|
||||
/* We respond when we are done */
|
||||
if (isLast) {
|
||||
res.end('Thanks for the data!');
|
||||
}
|
||||
});
|
||||
|
||||
res.onAborted(() => {
|
||||
/* Request was prematurely aborted, stop reading */
|
||||
console.log('Eh, okay. Thanks for nothing!');
|
||||
});
|
||||
}).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