From 9a328047013041cf9b8b03bd720f89d6c9e92a22 Mon Sep 17 00:00:00 2001 From: moranbw Date: Mon, 10 Feb 2020 20:30:29 -0500 Subject: [PATCH] updated react app to serve from root by default. also updated readme to explain how you can proxy to a subpath, still. --- README.md | 11 +++++++---- client/package.json | 4 ++-- server.js | 12 ++++++------ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 982c873..8a27199 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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; diff --git a/client/package.json b/client/package.json index cc8eb59..d9272ab 100644 --- a/client/package.json +++ b/client/package.json @@ -31,6 +31,6 @@ "last 1 safari version" ] }, - "proxy": "http://localhost:5000/speedtest", - "homepage": "https://yourserver.com/speedtest" + "proxy": "http://localhost:5000/", + "homepage": "." } diff --git a/server.js b/server.js index 4d51898..e294ae0 100644 --- a/server.js +++ b/server.js @@ -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()); @@ -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}`); @@ -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 { @@ -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