Make the two runtimes capable of sharing the same example

This commit is contained in:
Alex Hultman 2018-11-04 23:46:50 +01:00
parent 63101ad671
commit 0393102704
3 changed files with 21 additions and 23 deletions

View file

@ -1,16 +0,0 @@
/* This is a script not for Node.js but runs completely stand-alone using loopery */
print('Welcome to loopery!');
const port = 3000;
App().get('/hello', (res, req) => {
res.end('world!');
}).get('/*', (res, req) => {
res.writeHeader('content-type', 'text/html; charset= utf-8').end(req.getHeader('user-agent') + ' är din user agent, biatch!');
}).listen(port, (token) => {
if (token) {
print('Listening to port ' + port);
} else {
print('Failed to listen to port ' + port);
}
});

View file

@ -1,9 +1,9 @@
const uWS = require('../dist/uws.js');
/* The stand-alone runtime has uWS namespace already loaded. */
var uWS = uWS ? uWS : require('../dist/uws.js');
const world = 'Strings are slower than ArrayBuffer but who cares for demo purose!';
const port = 3000;
const world = new (require('util').TextEncoder)().encode('World!');
uWS.App().get('/hello', (res, req) => {
res.end(world);
}).get('/*', (res, req) => {
@ -16,4 +16,5 @@ uWS.App().get('/hello', (res, req) => {
}
});
/* This is not true for stand-alone */
console.log('Timers will not work until us_loop_integrate is done');