Skip to content

Commit

Permalink
updated react app to serve from root by default. also updated readme …
Browse files Browse the repository at this point in the history
…to explain how you can proxy to a subpath, still.
  • Loading branch information
moranbw committed Feb 11, 2020
1 parent 1d55e2e commit 9a32804
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Example use-case: test "wired speed" of a computer connected via hard-wired ethe
### docker install
-----
* `docker run -d -p 5000:5000 --name speedtest-app bwmoran/speedtest-app`
* application should be running at [http://localhost:5000/speedtest](http://)
* application should be running at [http://localhost:5000](http://)


### old-fashioned install
Expand All @@ -28,15 +28,18 @@ Example use-case: test "wired speed" of a computer connected via hard-wired ethe
* `npm run deploy`
* run application
* `npm run start`
* application should be running at [http://localhost:5000/speedtest](http://)
* application should be running at [http://localhost:5000](http://)


### proxy example
-----
**nginx**
```nginx
location /speedtest {
proxy_pass http://your_ip_or_host:5000;
location = /speedtest {
return 302 /speedtest/;
}
location /speedtest/ {
proxy_pass http://your_ip_or_host:5000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Expand Down
4 changes: 2 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
"last 1 safari version"
]
},
"proxy": "http://localhost:5000/speedtest",
"homepage": "https://yourserver.com/speedtest"
"proxy": "http://localhost:5000/",
"homepage": "."
}
12 changes: 6 additions & 6 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const express = require('express');
const { exec } = require('child_process');
const fs = require('fs');
const app = express();
const port = process.env.PORT || 5000;
const port = 5000;

app.use(express.json());

Expand All @@ -15,14 +15,14 @@ app.use(function (req, res, next) {
const server = require('http').Server(app);

// create a GET route
app.get('/speedtest/test', (req, res) => {
app.get('/test', (req, res) => {
console.log(req.body);

exec('speedtest --accept-license --format=json', (err, stdout, stderr) => {
if (err) {
//some err occurred
console.error(err)
res.send({ "error": "There was an error while running the speed test." })
console.error(err);
res.send({ "error": "There was an error while running the speed test." });
} else {
// the *entire* stdout and stderr (buffered)
console.log(`stdout: ${stdout}`);
Expand All @@ -40,7 +40,7 @@ app.get('/speedtest/test', (req, res) => {
"isp": result.isp,
"server name": result.server.name,
"server location": result.server.location
}
};
res.send(response);
}
else {
Expand All @@ -53,7 +53,7 @@ app.get('/speedtest/test', (req, res) => {
//if built client exists, serve static content
if (fs.existsSync("client/build/index.html")) {
console.log("production");
app.use('/speedtest', express.static('client/build'));
app.use(express.static('client/build'));
}

// console.log that your server is up and running
Expand Down

0 comments on commit 9a32804

Please sign in to comment.