Skip to content

Commit

Permalink
Add ability to connect remotely
Browse files Browse the repository at this point in the history
  • Loading branch information
HPWebdeveloper committed Feb 4, 2024
1 parent 11e5c19 commit b17f84e
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 49 deletions.
9 changes: 9 additions & 0 deletions config/failedjobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,13 @@

'middleware' => ['web'],



'axios_base_url' => env('AXIOS_BASE_URL', ''),

'server_access_token' => env('FAILEDJOBS_SERVER_ACCESS_TOKEN'),

'dashboard_access_token' => env('FAILEDJOBS_DASHBOARD_ACCESS_TOKEN'),


];
42 changes: 21 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"/app.js": "/app.js?id=3bbefa933420c320ec2937071af50c33",
"/app.js": "/app.js?id=c71be819f209fec26be0a8f6d6224d0e",
"/app-dark.css": "/app-dark.css?id=2f61dc709214cae8cc7a77603b1ba389",
"/app.css": "/app.css?id=43830728727b0f59dc16b9a11f09f077",
"/img/failedjobs.svg": "/img/failedjobs.svg?id=904d5b5185fefb09035384e15bfca765",
Expand Down
4 changes: 3 additions & 1 deletion resources/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ if (token) {

Vue.use(VueRouter);

Vue.prototype.$http = axios.create();
Vue.prototype.$http = axios.create({
baseURL: window.FailedJobs.axios_base_url,
});

window.FailedJobs.basePath = '/' + window.FailedJobs.path;

Expand Down
4 changes: 2 additions & 2 deletions resources/js/screens/failedJobs/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default {
*/
checkForNewJobs() {
if (!this.$root.autoLoadsNewEntries) {
this.$http.get(FailedJobs.basePath + `/api/?page=1&perPage=1`)
this.$http.get(FailedJobs.basePath + `/api/?page=1&perPage=1&access_token=${window.FailedJobs.access_token}`)
.then(response => {
const newLatestJob = response.data.data[0];
if (newLatestJob && newLatestJob.uuid !== this.latestJobUuid) {
Expand Down Expand Up @@ -91,7 +91,7 @@ export default {
this.ready = false;
}
this.$http.get(FailedJobs.basePath + `/api/?page=${this.page}&perPage=${this.perPage}`)
this.$http.get(FailedJobs.basePath + `/api/?page=${this.page}&perPage=${this.perPage}&access_token=${window.FailedJobs.access_token}`)
.then(response => {
// Only update jobs list if auto-loading is enabled or it's not a refresh
if (this.$root.autoLoadsNewEntries || !refreshing) {
Expand Down
3 changes: 2 additions & 1 deletion resources/js/screens/failedJobs/job.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export default {
methods: {
loadFailedJob(id) {
this.ready = false;
this.$http.get(FailedJobs.basePath + '/api/' + id)
const uri = `${FailedJobs.basePath}/api/${id}?access_token=${window.FailedJobs.access_token}`;
this.$http.get(uri)
.then(response => {
this.job = response.data;
console.log(this.job);
Expand Down
19 changes: 0 additions & 19 deletions src/Http/Controllers/Controller.php

This file was deleted.

14 changes: 13 additions & 1 deletion src/Http/Controllers/FailedJobsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@

namespace HPWebdeveloper\LaravelFailedJobs\Http\Controllers;

use HPWebdeveloper\LaravelFailedJobs\Http\Middleware\AuthorizeFailedJobsByAccessToken;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Routing\Controller as BaseController;


class FailedJobsController extends Controller
class FailedJobsController extends BaseController
{

/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware(AuthorizeFailedJobsByAccessToken::class);
}

public function index(Request $request)
{
$perPage = 50;
Expand Down
19 changes: 17 additions & 2 deletions src/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@

namespace HPWebdeveloper\LaravelFailedJobs\Http\Controllers;

use HPWebdeveloper\LaravelFailedJobs\Http\Middleware\Authenticate;
use Illuminate\Support\Facades\App;
use HPWebdeveloper\LaravelFailedJobs\FailedJobs;
use Illuminate\Routing\Controller as BaseController;

class HomeController extends Controller
class HomeController extends BaseController
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware(Authenticate::class);
}

/**
* Single page application catch-all route.
*
Expand All @@ -16,7 +28,10 @@ public function index()
{
return view('failedjobs::layout', [
'assetsAreCurrent' => FailedJobs::assetsAreCurrent(),
'failedJobsScriptVariables' => FailedJobs::scriptVariables(),
'failedJobsScriptVariables' => array_merge(FailedJobs::scriptVariables(), [
'axios_base_url' => config('failedjobs.axios_base_url'),
'access_token' => config('failedjobs.dashboard_access_token'),
]),
'isDownForMaintenance' => App::isDownForMaintenance(),
]);
}
Expand Down
28 changes: 28 additions & 0 deletions src/Http/Middleware/AuthorizeFailedJobsByAccessToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace HPWebdeveloper\LaravelFailedJobs\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Http\JsonResponse;

class AuthorizeFailedJobsByAccessToken
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): JsonResponse|Response
{
// Using `input` method allows checking either query string or request body
if (config('failedjobs.server_access_token') === $request->input('access_token', false)) {
return $next($request);
}

return new JsonResponse([
'message' => 'Unauthorized',
], Response::HTTP_UNAUTHORIZED);
}
}

0 comments on commit b17f84e

Please sign in to comment.