Skip to content

Commit

Permalink
v 1.0.7
Browse files Browse the repository at this point in the history
* swith from .dev to .localhost (changing app name to LocalhostD)
* rewrite using create-react-app
* show console on application domain
  • Loading branch information
layerssss committed Oct 27, 2018
1 parent 7a397ad commit d1699ff
Show file tree
Hide file tree
Showing 65 changed files with 12,013 additions and 14,478 deletions.
5 changes: 3 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
static/vendor
dist
/node_modules
/dist
/ui_build
13 changes: 7 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"env": {
"es6": true,
"node": true
"node": true,
"browser": false
},
"extends": ["eslint:recommended", "prettier"],
"parserOptions": { "ecmaVersion": 9 },
"extends": ["eslint:recommended", "react-app", "prettier"],
"rules": {
"no-console": 0,
"no-unused-vars": 0,
"linebreak-style": ["error", "unix"],
"semi": ["error", "always"]
"semi": ["error", "always"],
"no-var": ["error"],
"prefer-const": ["error"]
}
}
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/node_modules
/dist
/ui_build

*.log
node_modules
dist
.npmrc
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/dist
/src

*.log
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# bnb
# LocalhostD

Run and serve your web apps in .dev domains on your develop machine.
Run and serve your web apps in .test domains on your develop machine.

![a](https://user-images.githubusercontent.com/1559832/27260786-ccb150de-5488-11e7-9cb5-44b98d5fdad2.gif)

Expand All @@ -23,16 +23,16 @@ Comparing to hotel, this project comes with a few extra features:
If you prefer launching and keeping it by CLI, then

```
npm install bnb -g
bnb server
npm install localhostd -g
localhostd server
```

... or if you prefer launching it as a GUI staying as a tray icon, [download the latest release](https://github.com/layerssss/bnb/releases).
... or if you prefer launching it as a GUI staying as a tray icon, [download the latest release](https://github.com/layerssss/localhostd/releases).


## Usage

Configure your brower to use `http://localhost:2999` as HTTP/HTTPS proxy. Then add your apps in http://bnb.dev/ (or in GUI), specifying the directory and the command to run your application.
Configure your brower to use `http://localhost:2999` as HTTP/HTTPS proxy. Then add your apps in http://localhostd.test/ (or in GUI), specifying the directory and the command to run your application.

Make sure they listen to the HTTP port number specified in the `PORT` enviroment variable. Here are some examples commands:

Expand All @@ -42,11 +42,11 @@ Make sure they listen to the HTTP port number specified in the `PORT` enviroment
* `python -m SimpleHTTPServer $PORT`
* `php -S 127.0.0.1:$PORT`

Then click the 🌎 button in the app details to go to its `.dev` domain. `bnb` will launch your app for you.
Then click the 🌎 button in the app details to go to its `.test` domain. `localhostd` will launch your app for you.

## Self-signed SSL

`bnb` generates a self-signed CA key-pair and stores it with other data at `~/.bnb.json`. Then it signs SSL certificate for each `.dev` domain when requested. So SSL works out of box, just by going to `https://my-app.dev/`. But if want to see a 'greenlock', i.e. to make your browser trust `bnb`, you need to mark your self-signed CA as trusted in browser or OS.
`localhostd` generates a self-signed CA key-pair and stores it with other data at `~/.localhostd.json`. Then it signs SSL certificate for each `.test` domain when requested. So SSL works out of box, just by going to `https://my-app.test/`. But if want to see a 'greenlock', i.e. to make your browser trust `localhostd`, you need to mark your self-signed CA as trusted in browser or OS.

## License

Expand Down
81 changes: 37 additions & 44 deletions bin/app.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,26 @@
var electron = require("electron");
var Path = require("path");
var Utility = require("../lib/utility.js");
const electron = require("electron");
const Path = require("path");

var app, tray, App;
const waitDeath = require("../lib/wait_death.js");

var handleFatelError = error => {
console.error(error);
electron.dialog.showMessageBox(
null,
{
type: "error",
title: "Fatel error",
message: error.message
},
() => {
process.exit(1);
}
);
};

electron.app.on("ready", () => {
electron.app.on("ready", () =>
Promise.resolve()
.then(() => {
App = require("../lib/app.js");
app = new App({
.then(async () => {
const App = require("../lib/app.js");
const app = new App({
port: 2999
});
tray = new electron.Tray(Path.join(__dirname, "../static/tray.png"));
})
.then(() => app.listen())
.then(() => tray.setToolTip("Bnb is running..."))
.then(() => {
tray.on("double-click", () =>
Promise.resolve()
.then(() => app.showWindow())
.catch(handleFatelError)
);
const tray = new electron.Tray(Path.join(__dirname, "../lib/tray.png"));
await app.listen();
tray.setToolTip("LocalhostD is running...");
tray.on("double-click", () => app.showWindow());

tray.setContextMenu(
electron.Menu.buildFromTemplate([
{
label: "Open",
click: () => {
Promise.resolve()
.then(() => app.showWindow())
.catch(handleFatelError);
app.showWindow();
}
},
{
Expand All @@ -55,17 +31,34 @@ electron.app.on("ready", () => {
}
])
);
})
.then(() => {
if (process.platform == "darwin") electron.app.dock.hide();

if (process.platform === "darwin") electron.app.dock.hide();

electron.app.on("activate", () => {
Promise.resolve()
.then(() => app.showWindow())
.catch(handleFatelError);
app.showWindow();
});

electron.app.on("window-all-closed", () => {});

const signal = await waitDeath();

// eslint-disable-next-line no-console
console.log(`received ${signal}`);
electron.app.exit();
})
.catch(error => {
// eslint-disable-next-line no-console
console.error(error.stack);
electron.dialog.showMessageBox(
null,
{
type: "error",
title: "Fatel error",
message: `LocalhostD has encountered an error: \n${error.message}`
},
() => {
process.exit(1);
}
);
})
.catch(handleFatelError);
});
);
73 changes: 0 additions & 73 deletions bin/bnb.js

This file was deleted.

57 changes: 57 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env node

const Path = require("path");
const Commander = require("commander");
const Server = require("../lib/server.js");
const UpdateNotifier = require("update-notifier");
const pkg = require("../package.json");
const waitDeath = require("../lib/wait_death.js");

UpdateNotifier({
pkg
}).notify();

Commander.version(pkg.version)
.option("-d --debug", "enable debug")
.option(
" --state-file [string]",
"state file, default: ~/.localhostd.json",
Path.join(process.env["HOME"] || process.env["HOMEPATH"], ".localhostd.json")
);

Commander.command("server")
.option(
"-p, --port [integer]",
"HTTP port, default: 2999",
(i, d) => parseInt(i || d),
2999
)
.option("-b, --bind [string]", "HTTP bind, default: 127.0.0.1", "127.0.0.1")
.action(options =>
Promise.resolve()
.then(async () => {
const server = new Server(Commander);
await server.listen(options);

// eslint-disable-next-line no-console
console.log(server.getUsageMessage());

const signal = await waitDeath();

// eslint-disable-next-line no-console
console.log(`received ${signal}`);

process.exit(0);
})
.catch(error => {
// eslint-disable-next-line no-console
console.error(
Commander.debug
? error.stack
: `LocalhostD has encountered an error: \n${error.message}`
);
process.exit(1);
})
);

Commander.parse(process.argv);
46 changes: 46 additions & 0 deletions bin/ui_build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
process.env.NODE_ENV = "production";
process.env.BABEL_ENV = "production";

require("react-scripts/config/env");

const fs = require("fs-extra");
const path = require("path");
const paths = require("react-scripts/config/paths");

paths.appBuild = path.join(__dirname, "../ui_build");
paths.servedPath = "./";

const webpack = require("webpack");
const config = require("react-scripts/config/webpack.config.prod.js");

// removes react-dev-utils/webpackHotDevClient.js at first in the array
// config.entry.shift();

const webpackConfigured = webpack(config);

function callback(err, stats) {
if (err) {
// eslint-disable-next-line no-console
console.error(err);
} else {
copyPublicFolder();
}
if (stats)
// eslint-disable-next-line no-console
console.error(
stats.toString({
chunks: false,
colors: true
})
);
}

function copyPublicFolder() {
fs.copySync(paths.appPublic, paths.appBuild, {
dereference: true,
filter: file => file !== paths.appHtml
});
}

if (process.env.LOCALHOSTD_DEV_WATCH) webpackConfigured.watch({}, callback);
else webpackConfigured.run(callback);
Loading

0 comments on commit d1699ff

Please sign in to comment.