File tree 15 files changed +278
-8
lines changed
15 files changed +278
-8
lines changed Original file line number Diff line number Diff line change
1
+ {
2
+ "directory": "src/public/vendor"
3
+ }
Original file line number Diff line number Diff line change 3
3
.env
4
4
.project
5
5
/node_modules /
6
- /design /
7
- /fonts /
8
- /mockups /
9
6
/src /public /vendor /
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " example-1" ,
3
+ "version" : " 0.0.0" ,
4
+ "authors" : [
5
+ " Dimitrios C. Michalakos <dimitris@jmike.gr>"
6
+ ],
7
+ "license" : " MIT" ,
8
+ "dependencies" : {
9
+ "bluebird" : " ~2.10.2"
10
+ }
11
+ }
Original file line number Diff line number Diff line change 19
19
"private" : true ,
20
20
"dependencies" : {
21
21
"babel" : " ^5.8.23" ,
22
- "hapi" : " ^10.0.0"
22
+ "hapi" : " ^10.0.0" ,
23
+ "inert" : " ^3.1.0"
23
24
}
24
25
}
Original file line number Diff line number Diff line change
1
+ <!doctype html>
2
+ < html class ="no-js " lang ="">
3
+ < head >
4
+ < meta http-equiv ="Content-Type " content ="text/html; charset=UTF-8 " />
5
+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge,chrome=1 " />
6
+ < title > History of async JS - Example 1</ title >
7
+ < meta name ="description " content ="" />
8
+ < meta name ="viewport " content ="width=device-width, initial-scale=1 " />
9
+ < link rel ="apple-touch-icon " href ="apple-touch-icon.png " />
10
+ </ head >
11
+ < body >
12
+ < script type ="text/javascript " src ="../vendor/bluebird/js/browser/bluebird.js "> </ script >
13
+ < script type ="text/javascript " src ="./main.js "> </ script >
14
+ </ body >
15
+ </ html >
Original file line number Diff line number Diff line change
1
+ function say ( q ) {
2
+ var resolver = function ( resolve , reject ) {
3
+ var xhr = new XMLHttpRequest ( ) ;
4
+ xhr . open ( 'GET' , 'http://localhost:5000/mirror?q=' + q , true ) ;
5
+ xhr . onreadystatechange = function ( ) {
6
+ if ( this . readyState == 4 ) {
7
+ if ( this . status == 200 ) {
8
+ resolve ( this . responseText ) ;
9
+ } else {
10
+ reject ( new Error ( 'Unspecified error occured' ) ) ;
11
+ }
12
+ }
13
+ } ;
14
+ xhr . send ( ) ;
15
+ } ;
16
+
17
+ return new Promise ( resolver ) ;
18
+ }
19
+
20
+ console . time ( 'timer' ) ;
21
+ say ( 'Hello' )
22
+ . then ( function ( text ) {
23
+ console . log ( text ) ;
24
+ } )
25
+ . catch ( function ( err ) {
26
+ console . error ( err ) ;
27
+ } )
28
+ . finally ( function ( ) {
29
+ console . timeEnd ( 'timer' ) ;
30
+ } )
Original file line number Diff line number Diff line change
1
+ <!doctype html>
2
+ < html class ="no-js " lang ="">
3
+ < head >
4
+ < meta http-equiv ="Content-Type " content ="text/html; charset=UTF-8 " />
5
+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge,chrome=1 " />
6
+ < title > History of async JS - Example 1</ title >
7
+ < meta name ="description " content ="" />
8
+ < meta name ="viewport " content ="width=device-width, initial-scale=1 " />
9
+ < link rel ="apple-touch-icon " href ="apple-touch-icon.png " />
10
+ </ head >
11
+ < body >
12
+ < script type ="text/javascript " src ="../vendor/bluebird/js/browser/bluebird.js "> </ script >
13
+ < script type ="text/javascript " src ="./main.js "> </ script >
14
+ </ body >
15
+ </ html >
Original file line number Diff line number Diff line change
1
+ function say ( q ) {
2
+ var resolver = function ( resolve , reject ) {
3
+ var xhr = new XMLHttpRequest ( ) ;
4
+ xhr . open ( 'GET' , 'http://localhost:5000/mirror?q=' + q , true ) ;
5
+ xhr . onreadystatechange = function ( ) {
6
+ if ( this . readyState == 4 ) {
7
+ if ( this . status == 200 ) {
8
+ resolve ( this . responseText ) ;
9
+ } else {
10
+ reject ( new Error ( 'Unspecified error occured' ) ) ;
11
+ }
12
+ }
13
+ } ;
14
+ xhr . send ( ) ;
15
+ } ;
16
+
17
+ return new Promise ( resolver ) ;
18
+ }
19
+
20
+ console . time ( 'timer' ) ;
21
+ say ( 'Hello' )
22
+ . then ( function ( text ) {
23
+ console . log ( text ) ;
24
+ return say ( 'mr.' ) ;
25
+ } )
26
+ . then ( function ( text ) {
27
+ console . log ( text ) ;
28
+ return say ( 'developer' ) ;
29
+ } )
30
+ . then ( function ( text ) {
31
+ console . log ( text ) ;
32
+ } )
33
+ . catch ( function ( err ) {
34
+ console . error ( err ) ;
35
+ } )
36
+ . finally ( function ( ) {
37
+ console . timeEnd ( 'timer' ) ;
38
+ } )
Original file line number Diff line number Diff line change
1
+ <!doctype html>
2
+ < html class ="no-js " lang ="">
3
+ < head >
4
+ < meta http-equiv ="Content-Type " content ="text/html; charset=UTF-8 " />
5
+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge,chrome=1 " />
6
+ < title > History of async JS - Example 1</ title >
7
+ < meta name ="description " content ="" />
8
+ < meta name ="viewport " content ="width=device-width, initial-scale=1 " />
9
+ < link rel ="apple-touch-icon " href ="apple-touch-icon.png " />
10
+ </ head >
11
+ < body >
12
+ < script type ="text/javascript " src ="../vendor/bluebird/js/browser/bluebird.js "> </ script >
13
+ < script type ="text/javascript " src ="./main.js "> </ script >
14
+ </ body >
15
+ </ html >
Original file line number Diff line number Diff line change
1
+ function say ( q ) {
2
+ var resolver = function ( resolve , reject ) {
3
+ var xhr = new XMLHttpRequest ( ) ;
4
+ xhr . open ( 'GET' , 'http://localhost:5000/mirror?q=' + q , true ) ;
5
+ xhr . onreadystatechange = function ( ) {
6
+ if ( this . readyState == 4 ) {
7
+ if ( this . status == 200 ) {
8
+ resolve ( this . responseText ) ;
9
+ } else {
10
+ reject ( new Error ( 'Unspecified error occured' ) ) ;
11
+ }
12
+ }
13
+ } ;
14
+ xhr . send ( ) ;
15
+ } ;
16
+
17
+ return new Promise ( resolver ) ;
18
+ }
19
+
20
+ console . time ( 'timer' ) ;
21
+ Promise . all ( [
22
+ say ( 'Hello' ) ,
23
+ say ( 'mr.' ) ,
24
+ say ( 'developer' )
25
+ ] )
26
+ . then ( function ( arr ) {
27
+ console . log ( arr . join ( ' ' ) ) ;
28
+ } )
29
+ . catch ( function ( err ) {
30
+ console . error ( err ) ;
31
+ } )
32
+ . finally ( function ( ) {
33
+ console . timeEnd ( 'timer' ) ;
34
+ } )
Original file line number Diff line number Diff line change
1
+ <!doctype html>
2
+ < html class ="no-js " lang ="">
3
+ < head >
4
+ < meta http-equiv ="Content-Type " content ="text/html; charset=UTF-8 " />
5
+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge,chrome=1 " />
6
+ < title > History of async JS - Example 1</ title >
7
+ < meta name ="description " content ="" />
8
+ < meta name ="viewport " content ="width=device-width, initial-scale=1 " />
9
+ < link rel ="apple-touch-icon " href ="apple-touch-icon.png " />
10
+ </ head >
11
+ < body >
12
+ < script type ="text/javascript " src ="../vendor/bluebird/js/browser/bluebird.js "> </ script >
13
+ < script type ="text/javascript " src ="./main.js "> </ script >
14
+ </ body >
15
+ </ html >
Original file line number Diff line number Diff line change
1
+ function say ( q ) {
2
+ var resolver = function ( resolve , reject ) {
3
+ var xhr = new XMLHttpRequest ( ) ;
4
+ xhr . open ( 'GET' , 'http://localhost:5000/mirror?q=' + q , true ) ;
5
+ xhr . onreadystatechange = function ( ) {
6
+ if ( this . readyState == 4 ) {
7
+ if ( this . status == 200 ) {
8
+ resolve ( this . responseText ) ;
9
+ } else {
10
+ reject ( new Error ( 'Unspecified error occured' ) ) ;
11
+ }
12
+ }
13
+ } ;
14
+ xhr . send ( ) ;
15
+ } ;
16
+
17
+ return new Promise ( resolver ) ;
18
+ }
19
+
20
+ console . time ( 'timer' ) ;
21
+ Promise . props ( {
22
+ a : say ( 'Hello' ) ,
23
+ b : say ( 'mr.' ) ,
24
+ c : say ( 'developer' )
25
+ } )
26
+ . then ( function ( props ) {
27
+ console . log ( props . b + ' ' + props . c + ', ' + props . a ) ;
28
+ } )
29
+ . catch ( function ( err ) {
30
+ console . error ( err ) ;
31
+ } )
32
+ . finally ( function ( ) {
33
+ console . timeEnd ( 'timer' ) ;
34
+ } )
Original file line number Diff line number Diff line change
1
+ <!doctype html>
2
+ < html class ="no-js " lang ="">
3
+ < head >
4
+ < meta http-equiv ="Content-Type " content ="text/html; charset=UTF-8 " />
5
+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge,chrome=1 " />
6
+ < title > History of async JS - Example 1</ title >
7
+ < meta name ="description " content ="" />
8
+ < meta name ="viewport " content ="width=device-width, initial-scale=1 " />
9
+ < link rel ="apple-touch-icon " href ="apple-touch-icon.png " />
10
+ </ head >
11
+ < body >
12
+ < script type ="text/javascript " src ="../vendor/bluebird/js/browser/bluebird.js "> </ script >
13
+ < script type ="text/javascript " src ="./main.js "> </ script >
14
+ </ body >
15
+ </ html >
Original file line number Diff line number Diff line change
1
+ function say ( q ) {
2
+ var resolver = function ( resolve , reject ) {
3
+ var xhr = new XMLHttpRequest ( ) ;
4
+ xhr . open ( 'GET' , 'http://localhost:5000/mirror?q=' + q , true ) ;
5
+ xhr . onreadystatechange = function ( ) {
6
+ if ( this . readyState == 4 ) {
7
+ if ( this . status == 200 ) {
8
+ resolve ( this . responseText ) ;
9
+ } else {
10
+ reject ( new Error ( 'Unspecified error occured' ) ) ;
11
+ }
12
+ }
13
+ } ;
14
+ xhr . send ( ) ;
15
+ } ;
16
+
17
+ return new Promise ( resolver ) ;
18
+ }
19
+
20
+ console . time ( 'timer' ) ;
21
+ Promise . race ( [
22
+ say ( 'Mitsos' ) ,
23
+ say ( 'Kitsos' ) ,
24
+ say ( 'Koula' )
25
+ ] )
26
+ . then ( function ( winner ) {
27
+ console . log ( winner + ' wins!' ) ;
28
+ } )
29
+ . catch ( function ( err ) {
30
+ console . error ( err ) ;
31
+ } )
32
+ . finally ( function ( ) {
33
+ console . timeEnd ( 'timer' ) ;
34
+ } )
Original file line number Diff line number Diff line change 1
1
import Hapi from 'hapi' ;
2
+ import Inert from 'inert' ;
2
3
3
4
const server = new Hapi . Server ( ) ;
4
5
server . connection ( { port : parseInt ( process . env . PORT , 10 ) || 5000 } ) ;
5
6
6
- server . route ( [
7
- {
7
+ server . register ( [ Inert ] , ( err ) => {
8
+ if ( err ) return console . error ( err ) ;
9
+
10
+ server . route ( {
8
11
method : 'GET' ,
9
12
path : '/mirror' ,
10
13
handler : ( request , reply ) => {
11
14
setTimeout ( ( ) => {
12
15
reply ( request . query . q ) . type ( 'text/plain' ) ;
13
16
} , 5000 * Math . random ( ) ) ;
14
17
}
15
- }
16
- ] ) ;
18
+ } ) ;
19
+
20
+ server . route ( {
21
+ method : 'GET' ,
22
+ path : '/{param*}' ,
23
+ handler : {
24
+ directory : {
25
+ path : `${ __dirname } /public`
26
+ }
27
+ }
28
+ } ) ;
29
+ } ) ;
17
30
18
31
server . start ( ( ) => {
19
32
console . log ( `Server listening on port ${ server . info . port } ` ) ;
You can’t perform that action at this time.
0 commit comments