Skip to content

Commit 3ef95ba

Browse files
Adjusting project
1 parent b748e64 commit 3ef95ba

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.git/
3+
.gitignore

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
{
2-
"name": "tiny-livereload",
2+
"name": "@moraes/tiny-livereload-server",
33
"version": "1.0.0",
44
"description": "tiny web live reload",
55
"main": "src/index.js",
66
"repository": "git@github.com:fernandomoraes/tiny-livereload.git",
77
"author": "Fernando Moraes <fernandosdemoraes@gmail.com>",
88
"license": "MIT",
99
"private": false,
10+
"bin": "src/index.js",
1011
"dependencies": {
1112
"chokidar": "^3.4.2",
1213
"event-stream": "^4.0.1",
1314
"open": "^7.1.0",
1415
"send": "^0.17.1",
15-
"ws": "^7.3.1"
16+
"ws": "^7.3.1"
1617
}
1718
}

src/index.js

100644100755
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#! /usr/bin/env node
2+
13
const path = require('path');
24
const es = require('event-stream');
35

@@ -58,7 +60,7 @@ function startServer() {
5860
send(req, filePath)
5961
.on('stream', (stream) => {
6062
if (injectLiveReload) {
61-
injectLiveReloadFragment(stream);
63+
injectLiveReloadFragment(stream, res);
6264
}
6365
})
6466
.pipe(res);
@@ -68,12 +70,12 @@ function startServer() {
6870
.addListener('upgrade', (req, socket, head) =>
6971
ws.handleUpgrade(req, socket, head, (connection) => liveReloadWsConnections.push(connection))
7072
)
71-
.addListener('listening', () => console.log('server running...'))
73+
.addListener('listening', () => console.log(`server running on http://localhost:${SERVER_PORT} ...`))
7274
.addListener('listening', () => open(`http://localhost:${SERVER_PORT}`))
7375
.listen(SERVER_PORT);
7476
}
7577

76-
function injectLiveReloadFragment(stream) {
78+
function injectLiveReloadFragment(stream, res) {
7779
const newContentLength = res.getHeader('content-length') + LIVERELOAD_FRAGMENT.length;
7880
res.setHeader('content-length', newContentLength);
7981

0 commit comments

Comments
 (0)