frontfire 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/FrontFire.js +26 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontfire",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/FrontFire.js CHANGED
@@ -74,7 +74,7 @@ async function frontFire( isWatch )
74
74
  if ( true === isWatch )
75
75
  {
76
76
  opts[ "banner" ] = {
77
- js: "(() => { (new EventSource(\"/esbuild\")).addEventListener('change', () => location.reload()); })();"
77
+ js: "(() => { (new EventSource(\"/esbuild\")).addEventListener('change', () => location.reload() ); })();"
78
78
  };
79
79
  }
80
80
 
@@ -82,6 +82,13 @@ async function frontFire( isWatch )
82
82
 
83
83
  if ( true === isWatch )
84
84
  {
85
+ console.log( "Adding additional watcher..." );
86
+ fs.watchFile( `src${path.sep}index.html`, async ( curr, prev ) =>
87
+ {
88
+ console.log( "Index.html changed..." );
89
+ const result = await ctx.rebuild();
90
+ console.log( result );
91
+ });
85
92
  await ctx.watch();
86
93
  let { host, port } = await ctx.serve(
87
94
  {
@@ -89,6 +96,17 @@ async function frontFire( isWatch )
89
96
  }
90
97
  );
91
98
 
99
+
100
+ let sseResponse = null;
101
+ /*
102
+ // DOES NOT WORK
103
+ setInterval( () =>
104
+ {
105
+ console.log( "Sending sse..." );
106
+ sseResponse.write( 'data: esbuild' );
107
+ }, 5000 );
108
+ */
109
+
92
110
  // Then start a proxy server on port 3000
93
111
  http.createServer((req, res) => {
94
112
 
@@ -100,6 +118,7 @@ async function frontFire( isWatch )
100
118
  headers: req.headers,
101
119
  }
102
120
 
121
+
103
122
  // Check if path is a valid state route
104
123
  // then pass it as "index.html" to the server
105
124
 
@@ -115,8 +134,13 @@ async function frontFire( isWatch )
115
134
  // Otherwise, forward the response from esbuild to the client
116
135
  res.writeHead(proxyRes.statusCode, proxyRes.headers)
117
136
 
137
+ if ( req.url === '/esbuild' )
138
+ {
139
+ sseResponse = res;
140
+ }
141
+
118
142
  proxyRes.pipe(res, { end: true })
119
- })
143
+ });
120
144
 
121
145
  // Forward the body of the request to esbuild
122
146
  req.pipe(proxyReq, { end: true })