ericmdantas / aliv Goto Github PK
View Code? Open in Web Editor NEWLight, fast and powerful one liner live-reloading Node.js server.
License: MIT License
Light, fast and powerful one liner live-reloading Node.js server.
License: MIT License
Hi :)
The default ssl certs are invalid (invalid common name), personnally I use sslfie (https://github.com/mkropat/sslfie) to generate valid certificates, here is how I did to use aliv with valid local certs :
for example lets say my local project is called "foobar", so I added 127.0.0.1 foobar.io
to my hosts file then in the node_modules/aliv/lib/crt
folder I executed :
sslfie -o server.crt -k server.key foobar.io
To trust these new certificates :
sudo apt install libnss3-tools
certutil -d sql:$HOME/.pki/nssdb -A -t P -n "Foobar" -i server.crt
That's it, after restarting browser, I can go to https://foobar.io:1307/ without having any https certificates errors :)
Right now, even though aliv
will work on gulp, broccolli or any other build tool, it's only called once, when the user calls start()
.
From that point on, all the reloading logic is managed by aliv
itself - but - that's a bit selfish.
The user might want to use both aliv
's management of reloading and his own reload()
logic.
aliv
will keep doing its job to reload the browsers everytime some files change, but the user will be able to call reload()
on his own too.
Right now it's the root
folder and the folder that has index.html
.
Right now, every file being watched and modified will trigger the reload
call; but sometimes the user wants to control that in a different way, like executing other tasks before actually reloading the browser.
From time to time, this error occurs.
This only happens when the server (proxied) is taking a longer amount of time to respond and the client refreshes the page or makes another call to the same endpoint.
As of right now, aliv
's logs are pretty annoying and badly formatted.
It's a point that's easy enough to do and should be improved.
Use Brotli instead of GZIP?
expressjs/compression#71
https://blogs.akamai.com/2016/02/understanding-brotlis-potential.html
hi again :)
it would be great to redirect http to https when aliv is started in secure mode,
actually http is just not accessible.
I also tried with this conf :
{
"quiet": false,
"root": "dist/",
"port": 3000,
"host": "foobar.io",
"secure": true,
"proxy": true,
"proxyWhen": "/^http:/",
"proxyTarget": "https://foobar.io:3000"
}
Right now it's always this.root = process.cwd()
;
Use the compression
module - ref;
Depending on how the user separated the project's folder structure, source and test code might live inside the same folder.
aliv
should know how to ignore the test files by default. So, files that end with .spec.{js,ts,coffee}
, .test.{js,ts,coffee}
or _test.{js,ts,coffee}
should not be watched.
Even though express4 doesn't work out of the box with the http/2
module, one could do the following expressjs/express#2761:
const express = require('express');
const http2 = require('http2');
express.request.__proto__ = http2.IncomingMessage.prototype;
express.response.__proto__ = http2.ServerResponse.prototype;
const app = express();
// ...
Obviously that's a workaround and most likely have some caveats, like fallbacks and stuff like that. So we might be better of having the secure
and http2
options separated.
Hi team,
I launched web server using file .alivrc
with the following content:
{
"quiet": false,
"host": "0.0.0.0",
"port": 3000,
"secure": true,
"pathIndex": "client/dev",
"only": "client/dev/**/*",
"proxy": true,
"proxyWhen": "/api/path/to/proxy/*",
"proxyTarget": "http://proxy-to-my-target:8080"
}
and I cannot connect to the web server. Sound like it didn't get the host value to launch the server.
Thank you,
Toan Vu
Ref: http-party/node-http-proxy#304
<!-- index.html -->
<!doctype html>
<html>
<head>
<title>proxy_https</title>
</head>
<body>
<p id="info">!!!</p>
<script>
fetch('/api/abc')
.then(r => r.json())
.then(r => {
document.getElementById("info").innerText = r.msg;
})
</script>
</body>
</html>
// node's index.js
const express = require('express')
const app = express()
const fs = require('fs')
const path = require('path')
const https = require('https')
app.get('/api/abc', (req, res) => {
res.json({
msg: 'wut'
})
})
let options = {
ca: [
fs.readFileSync(path.join(__dirname, 'node_modules/aliv/lib/crt/server.csr'))
],
cert: fs.readFileSync(path.join(__dirname, 'node_modules/aliv/lib/crt/server.crt')),
key: fs.readFileSync(path.join(__dirname, 'node_modules/aliv/lib/crt/server.key'))
}
https.createServer(options, this._app)
.listen(9876, () => {
console.info(9876);
});
// .alivrc
{
"quiet": true,
"port": 3000,
"host": "127.0.0.1",
"secure": true,
"proxy": true,
"proxyWhen": "/api/*",
"proxyTarget": "https://127.0.0.1:9876"
}
// package.json
{
"name": "proxy_https",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"sc": "aliv",
"ss": "node index"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"aliv": "^1.4.1",
"express": "^4.14.0"
}
}
If you simply change everything that's in https
to http
, it works just fine.
To show things like version, values that are going to be used, etc.
Aliv crashes when ran with node >= 11.1.0
When we ran Aliv
using node version 11.1.0 or last one, the spdy version used by Aliv crashes...
class FastBuffer extends Uint8Array {} ^
RangeError: Invalid typed array length: -4095
It's related with spdy-http2/node-spdy#350
It should emit events the user could hook to and do whatever they wanted, things like:
let aliv = new Server();
aliv.on('start', () => {})
aliv.on('change', () => {})
aliv.on('reload', () => {})
aliv.on('proxy', () => {})
aliv.on('close', () => {})
aliv.on('error', () => {})
HMR would make the page update much faster than a full reload in big projects.
Obviously, it should be a flag. As simple as hmr
. The default should be false
, and, maybe in v2.0
, it should be true
.
References:
--quiet
will also work as -q
--noBrowser
will also work as -nb
--port
will also work as -p
--ignore
will also work as -ign
ignore
optiononly
optionpathIndex
optionproxy
optionhttps
optionWe should have some default ones:
The most common usage:
This depends on 1.1.0
.
The following routes serve the content correctly:
/
/something/1
The following don't:
/something/1/2
/something/1/2/3/
/something/1/2/3/there
A lot of times you'll want to do something before the browser is reloaded; like compiling less -> css
, ts -> js
and so on. That's where middlewares come in.
We should have a way the user can inform a bunch of callbacks and we'll run them before refreshing the page.
Been using this lib for a development server of a new project. Excellent work, thank you for having something simple, straightforward and powerful.
I have a suggested feature I'd like to see. Instead of reloading instantly on the first file change, setup a timeout that allows additional files to be affected before the reload.
This could be a simple "timeout" option added to the config, setting it to "100" would cause the server to wait 100 ms before sending a refresh after a file has changed.
This has come up as a problem quite a few times in my use case. I've got webpack watching for changes on typescript files to compile to js, then node-sass listening for changes to the sass files and compiling to CSS. Quite a few times I'll change CSS & TS files in the same save cycle, then when the server refreshes either the JS or CSS is a cycle behind (depending on which one compiled faster).
Having a static json in .alivrc
is not always ideal.. sometimes the user might want to use comments or write conditions to use a certain value - by using aliv.config.js
that'll be possible.
// .alivrc
{
"port": "1234",
"https": true
}
// aliv.config.js
module.exports = {
port: "1234",
root: process.cwd(),
http2: true, // doesn't work with node 11.x, see aliv#40
}
The user should use one or the other, but not both.
npm install aliv
npx aliv --port 8081 --http2 --noBrowser --root output
Trying to navigate to http://127.0.0.1:8081
from Firefox results in:
The connection was reset
Trying to navigate to http://127.0.0.1:8081
from from Chrome results in:
This page isn’t working
127.0.0.1 didn’t send any data.
ERR_EMPTY_RESPONSE
If I remove the --http2
, everything works as expected.
Node Version: v10.15.0
aliv Version: 1.11.4
This error occurs because the end of line is not set as lf
, it's set as whatever windows uses.
Create .editorconfig
file with:
[*]
end_of_line = lf
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 2
Priority: CLI args > .alivrc options
Get help with @cpaqui.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.