Added base url setting

This commit is contained in:
Henry Whitaker
2020-05-21 00:31:06 +01:00
parent faf292b68c
commit ad97579af4
40 changed files with 162 additions and 57 deletions

View File

@@ -1,6 +1,6 @@
# Speedtest Tracker
[![Docker pulls](https://img.shields.io/docker/pulls/henrywhitaker3/speedtest-tracker)](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [![last_commit](https://img.shields.io/github/last-commit/henrywhitaker3/Speedtest-Tracker)](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [![issues](https://img.shields.io/github/issues/henrywhitaker3/Speedtest-Tracker)](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) [![commit_freq](https://img.shields.io/github/commit-activity/m/henrywhitaker3/Speedtest-Tracker)](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) ![version](https://img.shields.io/badge/version-v1.4.1-success) [![license](https://img.shields.io/github/license/henrywhitaker3/Speedtest-Tracker)](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE)
[![Docker pulls](https://img.shields.io/docker/pulls/henrywhitaker3/speedtest-tracker)](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [![last_commit](https://img.shields.io/github/last-commit/henrywhitaker3/Speedtest-Tracker)](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [![issues](https://img.shields.io/github/issues/henrywhitaker3/Speedtest-Tracker)](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) [![commit_freq](https://img.shields.io/github/commit-activity/m/henrywhitaker3/Speedtest-Tracker)](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) ![version](https://img.shields.io/badge/version-v1.5.0-success) [![license](https://img.shields.io/github/license/henrywhitaker3/Speedtest-Tracker)](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE)
This program runs a speedtest check every hour and graphs the results. The back-end is written in [Laravel](https://laravel.com/) and the front-end uses [React](https://reactjs.org/). It uses the [speedtest-cli](https://github.com/sivel/speedtest-cli) package to get the data and uses [Chart.js](https://www.chartjs.org/) to plot the results.

View File

@@ -20,6 +20,12 @@ else
sed "s,SLACK_WEBHOOK=.*,SLACK_WEBHOOK=$SLACK_WEBHOOK," -i.bak .env
fi
if [ -z ${BASE_PATH+x} ]; then
echo "Base path is unset"
else
sed "s,BASE_PATH=.*,BASE_PATH=$BASE_PATH," -i.bak .env
fi
cd /app/site && php artisan migrate
cd /config

View File

@@ -23,3 +23,5 @@ SPEEDTEST_PASSWORD=
REMEMBER_DAYS=30
SLACK_WEBHOOK=
BASE_PATH=

View File

@@ -1,6 +1,6 @@
# Speedtest Tracker
[![Docker pulls](https://img.shields.io/docker/pulls/henrywhitaker3/speedtest-tracker)](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [![last_commit](https://img.shields.io/github/last-commit/henrywhitaker3/Speedtest-Tracker)](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [![issues](https://img.shields.io/github/issues/henrywhitaker3/Speedtest-Tracker)](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) ![version](https://img.shields.io/badge/version-v1.4.1-success) [![license](https://img.shields.io/github/license/henrywhitaker3/Speedtest-Tracker)](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE)
[![Docker pulls](https://img.shields.io/docker/pulls/henrywhitaker3/speedtest-tracker)](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [![last_commit](https://img.shields.io/github/last-commit/henrywhitaker3/Speedtest-Tracker)](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [![issues](https://img.shields.io/github/issues/henrywhitaker3/Speedtest-Tracker)](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) ![version](https://img.shields.io/badge/version-v1.5.0-success) [![license](https://img.shields.io/github/license/henrywhitaker3/Speedtest-Tracker)](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE)
This program runs a speedtest check every hour and graphs the results. The back-end is written in [Laravel](https://laravel.com/) and the front-end uses [React](https://reactjs.org/). It uses the [speedtest-cli](https://github.com/sivel/speedtest-cli) package to get the data and uses [Chart.js](https://www.chartjs.org/) to plot the results.

View File

@@ -35,4 +35,20 @@ class SettingsHelper {
return $setting;
}
public static function getBase()
{
$base = env('BASE_PATH', '/');
if($base == '') {
$base = '/';
} else {
if($base[0] != '/') {
$base = '/' . $base;
}
if($base[-1] != '/') {
$base = $base . '/';
}
}
return $base;
}
}

View File

@@ -48,4 +48,15 @@ class SettingsController extends Controller
'data' => $setting
], 200);
}
public function config()
{
$config = [
'base' => SettingsHelper::getBase()
];
return $config;
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Providers;
use App\Helpers\SettingsHelper;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
@@ -72,7 +73,7 @@ class RouteServiceProvider extends ServiceProvider
*/
protected function mapApiRoutes()
{
Route::prefix('api')
Route::prefix(SettingsHelper::getBase() . 'api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));

View File

@@ -1,4 +1,10 @@
{
"1.5.0": [
{
"description": "Added option to set base path",
"link": ""
}
],
"1.4.1": [
{
"description": "Updated laravel framework",

View File

@@ -7,7 +7,7 @@ return [
|--------------------------------------------------------------------------
*/
'version' => '1.4.1',
'version' => '1.5.0',
/*
|--------------------------------------------------------------------------

View File

@@ -0,0 +1,2 @@
c54307967324200175062a1527872f8ce69b945d {"key":"{\"terser\":\"4.6.10\",\"terser-webpack-plugin\":\"2.3.5\",\"terser-webpack-plugin-options\":{\"test\":new RegExp(\"\\\\.m?js(\\\\?.*)?$\", \"i\"),\"chunkFilter\":() => true,\"warningsFilter\":() => true,\"extractComments\":true,\"sourceMap\":true,\"cache\":true,\"cacheKeys\":defaultCacheKeys => defaultCacheKeys,\"parallel\":true,\"include\":undefined,\"exclude\":undefined,\"minify\":undefined,\"terserOptions\":{\"compress\":{\"warnings\":false},\"output\":{\"comments\":false}}},\"nodeVersion\":\"v10.19.0\",\"filename\":\"\\u002Fjs\\u002Fapp.js\",\"contentHash\":\"84614deb710d47a03e42\"}","integrity":"sha512-w8pTOgSs2Hfpyrhml44arTMG2YKT2JzE0hqYdA7kWeJswdu2MmDu0MDumKp5Z2nsQfpK9J9mwYu7i+BEApYLzw==","time":1590013678983,"size":2368305}

View File

@@ -0,0 +1,2 @@
b0bd509c98122036a9303b527d56eb993dc70952 {"key":"{\"terser\":\"4.6.10\",\"terser-webpack-plugin\":\"2.3.5\",\"terser-webpack-plugin-options\":{\"test\":new RegExp(\"\\\\.m?js(\\\\?.*)?$\", \"i\"),\"chunkFilter\":() => true,\"warningsFilter\":() => true,\"extractComments\":true,\"sourceMap\":true,\"cache\":true,\"cacheKeys\":defaultCacheKeys => defaultCacheKeys,\"parallel\":true,\"include\":undefined,\"exclude\":undefined,\"minify\":undefined,\"terserOptions\":{\"compress\":{\"warnings\":false},\"output\":{\"comments\":false}}},\"nodeVersion\":\"v10.19.0\",\"filename\":\"\\u002Fjs\\u002Fapp.js\",\"contentHash\":\"8df815f69f0203e553ed\"}","integrity":"sha512-PL+L+yKIvOR5XfftUSSgKLqhXzQvCElCMjv7cBB6NiA5zxS2gShYYn0bf3vyxkixRwiiu1CJae8BLqo2LsEwyA==","time":1590017361773,"size":2368166}

File diff suppressed because one or more lines are too long

View File

@@ -6,7 +6,7 @@ import Axios from 'axios';
export default class Backup extends Component {
backup = () => {
var url = '/api/backup';
var url = 'api/backup';
toast.info('Your backup has started downloading...');

View File

@@ -20,7 +20,7 @@ export default class Changelog extends Component {
}
getChangelog = () => {
Axios.get('/api/update/changelog')
Axios.get('api/update/changelog')
.then((resp) => {
this.setState({
changelog: resp.data.data,

View File

@@ -53,7 +53,7 @@ export default class Restore extends Component {
uploadFile = () => {
var data = { data: this.state.data };
var url = '/api/restore';
var url = 'api/restore';
Axios.post(url, data)
.then((resp) => {

View File

@@ -30,7 +30,7 @@ export default class HistoryGraph extends Component {
}
getData = (days = this.state.days) => {
var url = '/api/speedtest/time/' + days;
var url = 'api/speedtest/time/' + days;
Axios.get(url)
.then((resp) => {

View File

@@ -27,7 +27,7 @@ export default class LatestResults extends Component {
}
getData = () => {
var url = '/api/speedtest/latest';
var url = 'api/speedtest/latest';
Axios.get(url)
.then((resp) => {
@@ -45,7 +45,7 @@ export default class LatestResults extends Component {
}
newScan = () => {
var url = '/api/speedtest/run';
var url = 'api/speedtest/run';
Axios.get(url)
.then((resp) => {

View File

@@ -20,7 +20,7 @@ export default class TestsTable extends Component {
}
getData = (page = this.state.page) => {
var url = '/api/speedtest/?page=' + page;
var url = 'api/speedtest/?page=' + page;
Axios.get(url)
.then((resp) => {

View File

@@ -20,7 +20,7 @@ export default class Setting extends Component {
}
update = () => {
var url = '/api/settings';
var url = 'api/settings';
var data = {
name: this.state.name,
value: this.state.value

View File

@@ -33,7 +33,7 @@ export default class Settings extends Component {
}
getData = () => {
var url = '/api/settings/';
var url = 'api/settings/';
Axios.get(url)
.then((resp) => {

View File

@@ -25,7 +25,7 @@ export default class Version extends Component {
}
checkForUpdates = () => {
var url = '/api/update/check';
var url = 'api/update/check';
Axios.get(url)
.then((resp) => {
@@ -61,19 +61,19 @@ export default class Version extends Component {
updateProgress: 0,
});
toast.info('Downloading update');
Axios.get('/api/update/download')
Axios.get('api/update/download')
.then((resp) => {
this.setState({
updateProgress: 50,
});
toast.info('Extracting update');
Axios.get('/api/speedtest/extract')
Axios.get('api/speedtest/extract')
.then((resp) => {
this.setState({
updateProgress: 75,
});
toast.info('Applying update');
Axios.get('/api/update/move')
Axios.get('api/update/move')
.then((resp) => {
this.setState({
updateProgress: 100,

View File

@@ -24,7 +24,7 @@ export default class Login extends Component {
email: this.state.loginEmailInput,
password: this.state.loginPasswordInput
};
var url = '/api/auth/login';
var url = 'api/auth/login';
Axios.post(url, data)
.then((resp) => {

View File

@@ -15,26 +15,66 @@ export default class Index extends Component {
this.state = {
loading: true,
redirect: false
}
}
componentDidMount = () => {
this.getConfig();
}
getConfig() {
var url = 'api/settings/config';
Axios.get(url)
.then((resp) => {
window.config = resp.data;
this.setState({
loading: false,
redirect: true,
});
})
}
render() {
var loading = this.state.loading;
var redirect = this.state.redirect;
var baseSet = this.isset(window.config);
return (
<BrowserRouter>
<Route render={(props) => (<ToastContainer />)} />
<Switch>
<Route exact path="/" render={(props) => (
<div>
<HomePage />
</div>
)} />
<Route exact path="/error/:code" render={(props) => ( <ErrorPage code={props.match.params.code} /> )} />
<Route render={(props) => (<ErrorPage code="404" />)} />
</Switch>
</BrowserRouter>
);
if(loading) {
return (
<Loader />
);
} else {
if(baseSet && window.config.base) {
return (
<BrowserRouter>
<Route render={(props) => (<ToastContainer />)} />
<Switch>
<Route exact path={window.config.base} render={(props) => (
<div>
<HomePage />
</div>
)} />
<Route exact path={window.config.base + "error/:code"} render={(props) => ( <ErrorPage code={props.match.params.code} /> )} />
<Route render={(props) => (<ErrorPage code="404" />)} />
</Switch>
</BrowserRouter>
);
} else {
return (
<Loader />
);
}
}
}
isset(v) {
if(typeof v !== "undefined" || v !== null) {
return true;
} else {
return false;
}
}
}

View File

@@ -7,26 +7,26 @@
<meta name="author" content="Henry Whitaker">
<meta name="version" content="{{ config('speedtest.version', 'Unknown') }}">
<link href="/icons/themify/themify-icons.css" rel="stylesheet">
<link rel="stylesheet" href="/css/bootstrap.dark.min.css">
<link rel="stylesheet" href="/css/main.css">
<link href="{{ App\Helpers\SettingsHelper::getBase() }}files/icons/themify/themify-icons.css" rel="stylesheet">
<link rel="stylesheet" href="{{ App\Helpers\SettingsHelper::getBase() }}files/css/bootstrap.dark.min.css">
<link rel="stylesheet" href="{{ App\Helpers\SettingsHelper::getBase() }}files/css/main.css?v={{ str_replace('.', '-', config('speedtest.version')) }}">
<link rel="apple-touch-icon" sizes="57x57" href="/icons/fav/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="/icons/fav/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="/icons/fav/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/icons/fav/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/icons/fav/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/icons/fav/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/icons/fav/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/icons/fav/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="/icons/fav/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="/icons/fav/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="/icons/fav/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="/icons/fav/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="/icons/fav/favicon-16x16.png">
<link rel="manifest" href="/icons/fav/manifest.json">
<link rel="apple-touch-icon" sizes="57x57" href="{{ App\Helpers\SettingsHelper::getBase() }}files/icons/fav/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="{{ App\Helpers\SettingsHelper::getBase() }}files/icons/fav/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="{{ App\Helpers\SettingsHelper::getBase() }}files/icons/fav/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="{{ App\Helpers\SettingsHelper::getBase() }}files/icons/fav/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="{{ App\Helpers\SettingsHelper::getBase() }}files/icons/fav/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="{{ App\Helpers\SettingsHelper::getBase() }}files/icons/fav/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="{{ App\Helpers\SettingsHelper::getBase() }}files/icons/fav/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="{{ App\Helpers\SettingsHelper::getBase() }}files/icons/fav/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="{{ App\Helpers\SettingsHelper::getBase() }}files/icons/fav/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="{{ App\Helpers\SettingsHelper::getBase() }}files/icons/fav/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="{{ App\Helpers\SettingsHelper::getBase() }}files/icons/fav/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="{{ App\Helpers\SettingsHelper::getBase() }}files/icons/fav/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="{{ App\Helpers\SettingsHelper::getBase() }}files/icons/fav/favicon-16x16.png">
<link rel="manifest" href="{{ App\Helpers\SettingsHelper::getBase() }}files/icons/fav/manifest.json">
<meta name="msapplication-TileColor" content="#303030">
<meta name="msapplication-TileImage" content="/icons/fav/ms-icon-144x144.png">
<meta name="msapplication-TileImage" content="{{ App\Helpers\SettingsHelper::getBase() }}files/icons/fav/ms-icon-144x144.png">
<meta name="theme-color" content="#303030">
<title>{{ $title }}</title>
@@ -34,8 +34,8 @@
<body>
<div id="main"></div>
<script src="/js/jquery.min.js"></script>
<script src="/js/popper.min.js"></script>
<script src="/js/app.js"></script>
<script src="{{ App\Helpers\SettingsHelper::getBase() }}files/js/jquery.min.js"></script>
<script src="{{ App\Helpers\SettingsHelper::getBase() }}files/js/popper.min.js"></script>
<script src="{{ App\Helpers\SettingsHelper::getBase() }}files/js/app.js?v={{ str_replace('.', '-', config('speedtest.version')) }}"></script>
</body>
</html>

View File

@@ -58,6 +58,8 @@ Route::group([
'middleware' => 'api',
'prefix' => 'settings'
], function () {
Route::get('/config', 'SettingsController@config')
->name('settings.config');
Route::get('/', 'SettingsController@index')
->name('settings.index');
Route::put('/', 'SettingsController@store')

View File

@@ -1,5 +1,8 @@
<?php
use App\Helpers\SettingsHelper;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Route;
/*
@@ -13,8 +16,20 @@ use Illuminate\Support\Facades\Route;
|
*/
Route::get(SettingsHelper::getBase() . 'files/{path?}', function($file) {
$fileP = explode('?', $file)[0];
$fileP = public_path() . '/' . $fileP;
if(file_exists($fileP)) {
$contents = File::get($fileP);
$mime = \GuzzleHttp\Psr7\mimetype_from_filename($fileP);
return Response::make(File::get($fileP), 200, [ 'Content-type' => $mime ]);
} else {
abort(404);
}
})->where('path', '.*')
->name('files');
Route::get('/{path?}', function() {
return view('app', [ 'title' => 'Speedtest Checker' ]);
})
->where('path', '.*')
->name('react');
})->where('path', '^((?!\/api\/).)*$')
->name('react');