Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added basepath in express static resolve to permit use of custom basepath on every route #11

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ create directory for database
```
mkdir data
```
configure same base path on
configure same base path [at least '/'] on
- src/client/src/config.json
- src/config/server.json
- src/config/op.json


compile and build the client
```
cd client && npm i && npm run build && cd ..
Expand Down
4 changes: 2 additions & 2 deletions src/client/src/config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"basepath": "/oidc/rp/"
}
"basepath": "/oidc/rp/"
}
2 changes: 1 addition & 1 deletion src/client/src/containers/Main/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class Main extends Component {
<Sidebar {...this.props}/>

<main className="main">
<img className="agid-logo-print" src="/../../img/spid-agid-logo-lb.png" />
<img className="agid-logo-print" src="../img/spid-agid-logo-lb.png" />

<Breadcrumb {...this.props} user={this.state.user}/>
<Container fluid>
Expand Down
32 changes: 16 additions & 16 deletions src/client/src/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MainService {

login(options, callback_response, callback_error) {
Utility.log("GET /login");
axios.get(config.basepath + '/login?user=' + options.user + '&password=' + options.password)
axios.get(config.basepath + 'login?user=' + options.user + '&password=' + options.password)
.then((response)=> {
callback_response(response.data.apikey);
})
Expand All @@ -30,7 +30,7 @@ class MainService {

assert(callback_response, callback_error) {
Utility.log("GET /login/assert");
axios.get(config.basepath + '/login/assert')
axios.get(config.basepath + 'login/assert')
.then((response)=> {
callback_response(response.data);
})
Expand All @@ -56,7 +56,7 @@ class MainService {

getInfo(callback_response, callback_nosession, callback_error) {
Utility.log("GET /api/info");
axios.get(config.basepath + '/api/info?apikey=' + Utility.getApikey())
axios.get(config.basepath + 'api/info?apikey=' + Utility.getApikey())
.then(function(response) {
Utility.log("getInfo Success", response.data);
if(response.data.metadata.configuration && response.data.request) {
Expand All @@ -73,7 +73,7 @@ class MainService {

loadAllWorkspace(callback_response, callback_nosession, callback_error) {
Utility.log("GET /api/stores?apikey=" + Utility.getApikey());
axios.get(config.basepath + '/api/stores?apikey=' + Utility.getApikey())
axios.get(config.basepath + 'api/stores?apikey=' + Utility.getApikey())
.then(function(response) {
Utility.log("loadAllWorkspace Success", response.data);
callback_response(response.data);
Expand All @@ -90,7 +90,7 @@ class MainService {

loadWorkspace(store_type, callback_response, callback_nosession, callback_error) {
Utility.log("GET /api/store?store_type=" + store_type + "&apikey=" + Utility.getApikey());
axios.get(config.basepath + '/api/store?store_type=' + store_type + '&apikey=' + Utility.getApikey())
axios.get(config.basepath + 'api/store?store_type=' + store_type + '&apikey=' + Utility.getApikey())
.then(function(response) {
Utility.log("loadWorkspace Success", response.data);
callback_response(response.data);
Expand All @@ -106,7 +106,7 @@ class MainService {

saveWorkspace(data) {
Utility.log("POST /api/store", data);
axios.post(config.basepath + '/api/store?apikey=' + Utility.getApikey(), data)
axios.post(config.basepath + 'api/store?apikey=' + Utility.getApikey(), data)
.then(function(response) {
Utility.log("saveWorkspace Success", response.data);
})
Expand All @@ -117,7 +117,7 @@ class MainService {

resetWorkspace(store_type, callback_response, callback_error) {
Utility.log("DELETE /api/store?store_type=" + store_type);
axios.delete(config.basepath + '/api/store?store_type='+store_type+'&apikey=' + Utility.getApikey())
axios.delete(config.basepath + 'api/store?store_type='+store_type+'&apikey=' + Utility.getApikey())
.then(function(response) {
Utility.log("resetWorkspace Success", response.data);
callback_response();
Expand All @@ -130,7 +130,7 @@ class MainService {

downloadMetadata(url, type, callback_response, callback_error) {
Utility.log("POST /api/metadata/" + type + "/download");
axios.post(config.basepath + '/api/metadata/' + type + '/download?apikey=' + Utility.getApikey(), {url: url})
axios.post(config.basepath + 'api/metadata/' + type + '/download?apikey=' + Utility.getApikey(), {url: url})
.then(function(response) {
Utility.log("downloadMetadata Success", response.data);
callback_response(response.data);
Expand All @@ -143,7 +143,7 @@ class MainService {

checkMetadata(testcase, callback_response, callback_error) {
Utility.log("GET /api/metadata/check/" + testcase);
axios.get(config.basepath + '/api/metadata/check/' + testcase +
axios.get(config.basepath + 'api/metadata/check/' + testcase +
'?apikey=' + Utility.getApikey(), {timeout: 900000})
.then(function(response) {
Utility.log("checkMetadata Success", response.data);
Expand All @@ -157,7 +157,7 @@ class MainService {

getLastCheck(testcase, callback_response, callback_notfound, callback_error) {
Utility.log("GET /api/metadata/lastcheck/" + testcase);
axios.get(config.basepath + '/api/metadata/lastcheck/' + testcase + '?apikey=' + Utility.getApikey(), {timeout: 900000})
axios.get(config.basepath + 'api/metadata/lastcheck/' + testcase + '?apikey=' + Utility.getApikey(), {timeout: 900000})
.then(function(response) {
Utility.log("getLastCheck Success", response.data);
callback_response(response.data);
Expand All @@ -176,7 +176,7 @@ class MainService {
patchMetadataTest(testcase, test, data, callback_response, callback_notfound, callback_error) {
Utility.log("PATCH /api/metadata/" + testcase + "/" + test);
axios.patch(
config.basepath + '/api/metadata/' + testcase + '/' + test + '?apikey=' + Utility.getApikey(),
config.basepath + 'api/metadata/' + testcase + '/' + test + '?apikey=' + Utility.getApikey(),
{data: data},
{timeout: 900000}
)
Expand All @@ -198,7 +198,7 @@ class MainService {
patchOIDCTest(testcase, hook, test, data, callback_response, callback_notfound, callback_error) {
Utility.log("PATCH /api/oidc/report/" + testcase + "/" + hook + "/" + test);
axios.patch(
config.basepath + '/api/oidc/report/' + testcase + '/' + hook + "/" + test + '?apikey=' + Utility.getApikey(),
config.basepath + 'api/oidc/report/' + testcase + '/' + hook + "/" + test + '?apikey=' + Utility.getApikey(),
{data: data},
{timeout: 900000}
)
Expand All @@ -219,7 +219,7 @@ class MainService {

getTestSuite(testsuite, callback_response, callback_error) {
Utility.log("GET /api/test/suite/" + testsuite);
axios.get(config.basepath + '/api/test/suite/' + testsuite + '?apikey=' + Utility.getApikey(), {timeout: 900000})
axios.get(config.basepath + 'api/test/suite/' + testsuite + '?apikey=' + Utility.getApikey(), {timeout: 900000})
.then(function(response) {
Utility.log("getTestSuite Success", response.data);
callback_response(response.data);
Expand All @@ -232,7 +232,7 @@ class MainService {

startCheck(testcase, callback_response, callback_error) {
Utility.log("GET /api/oidc/check/" + testcase);
axios.get(config.basepath + '/api/oidc/check/' + testcase + '?apikey=' + Utility.getApikey(), {timeout: 900000})
axios.get(config.basepath + 'api/oidc/check/' + testcase + '?apikey=' + Utility.getApikey(), {timeout: 900000})
.then(function(response) {
Utility.log("startCheck Success", response.data);
callback_response(response.data);
Expand All @@ -245,7 +245,7 @@ class MainService {

getReport(callback_response, callback_notfound, callback_error) {
Utility.log("GET /api/oidc/report");
axios.get(config.basepath + '/api/oidc/report' + '?apikey=' + Utility.getApikey(), {timeout: 900000})
axios.get(config.basepath + 'api/oidc/report' + '?apikey=' + Utility.getApikey(), {timeout: 900000})
.then(function(response) {
Utility.log("getReport Success", response.data);
callback_response(response.data);
Expand All @@ -263,7 +263,7 @@ class MainService {

getServerInfo(callback_response, callback_error) {
Utility.log("GET /api/server-info");
axios.get(config.basepath + '/api/server-info', {timeout: 900000})
axios.get(config.basepath + 'api/server-info', {timeout: 900000})
.then(function(response) {
Utility.log("getServerInfo Success", response.data);
callback_response(response.data);
Expand Down
4 changes: 2 additions & 2 deletions src/client/src/views/Login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class Login extends Component {
Utility.setApikey(data.apikey);
Utility.log("Login result", Utility.isAuthenticated());
if(Utility.isAuthenticated()) {
window.location=config.basepath + "/worksave";
window.location=config.basepath + "worksave";
}
},
(tologin)=> {
if(tologin.remote) window.location=config.basepath + "/login";
if(tologin.remote) window.location=config.basepath + "login";
else {
this.setState({local_auth: true});
}
Expand Down
34 changes: 17 additions & 17 deletions src/client/src/views/Worksave/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,34 @@ import BlockUi from 'react-block-ui';
import './style.css';


function view(me) {
return (
function view(me) {
return (
<div id="Worksave" className="container container-login animated fadeIn">
<img className="img-fluid img-logo" src="img/logo.png" />
{ me.state.available_stores && me.state.available_stores.length>0 && (
{me.state.available_stores && me.state.available_stores.length > 0 && (
<div className="justify-content-center row mb-5 section-selector">
{ /*me.state.available_stores && me.state.available_stores.length==1 && (
<div className="title mb-3">È stato selezionato il...</div>
) */}
{ /*me.state.available_stores && me.state.available_stores.length>1 && (
<div className="title mb-3">Seleziona il metadata da utilizzare...</div>
) */}
{ me.isTypeAvailable('test') && (
{me.isTypeAvailable('test') && (
<div className="col col-12 col-md-12 col-lg-4">
<div className={`btn ${me.state.selected_type=='test'? "btn-selector btn-selector-active" : "btn-selector"}`}
onClick={()=>{me.setType('test')}}>
<div className={`btn ${me.state.selected_type == 'test' ? "btn-selector btn-selector-active" : "btn-selector"}`}
onClick={() => { me.setType('test') }}>

<img src="/img/metadata-test.svg" />
<img src="img/metadata-test.svg" />
<span className="d-sm-inline">Test Metadata</span>
</div>
</div>
)}
{ me.isTypeAvailable('prod') && (
{me.isTypeAvailable('prod') && (
<div className="col col-12 col-md-12 col-lg-4">
<div className={`btn ${me.state.selected_type=='prod'? "btn-selector btn-selector-active" : "btn-selector"}`}
onClick={()=>{me.setType('prod')}}>
<div className={`btn ${me.state.selected_type == 'prod' ? "btn-selector btn-selector-active" : "btn-selector"}`}
onClick={() => { me.setType('prod') }}>

<img src="/img/metadata-prod.svg" />
<img src="img/metadata-prod.svg" />
<span className="d-sm-inline">Production Metadata</span>
</div>
</div>
Expand All @@ -40,28 +40,28 @@ function view(me) {
<div className="justify-content-center row">
<div className="title mb-3">Please choice if you want to continue a previous report or start a new one...</div>
<div className="col col-12 col-md-12 col-lg-4">
<div className="card worksave-card"
onClick={()=>{me.startContinue()}}>
<div className="card worksave-card"
onClick={() => { me.startContinue() }}>

<div className="card-body">
<h1><img className="img-fluid worksave-img-continue" src="/img/continue.png" />Continue</h1>
<h1><img className="img-fluid worksave-img-continue" src="img/continue.png" />Continue</h1>
<p className="worksave-text-muted">Continue to work on the report from the previous session keeping all the stored test results</p>
</div>
</div>
</div>
<div className="col col-12 col-md-12 col-lg-4">
<div className="card worksave-card"
onClick={(e)=>{me.startNew()}}>
onClick={(e) => { me.startNew() }}>

<div className="card-body">
<h1><img className="img-fluid worksave-img-new" src="/img/new.png" />Start New</h1>
<h1><img className="img-fluid worksave-img-new" src="img/new.png" />Start New</h1>
<p className="worksave-text-muted">Start a new session to work on a blank report resetting all the previous stored results</p>
</div>
</div>
</div>
</div>
</div>
);
);
}

export default view;
3 changes: 2 additions & 1 deletion src/server/api/info.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const fs = require("fs-extra");
const Utility = require("../lib/utils");
const config_dir = require("../../config/dir.json");
const config_op = require("../../config/op.json");

module.exports = function(app, checkAuthorisation) {

// get info from session
app.get("/api/info", function(req, res) {
app.get(config_op.basepath+"api/info", function(req, res) {

// check if apikey is correct
if(!checkAuthorisation(req)) {
Expand Down
10 changes: 5 additions & 5 deletions src/server/api/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const jwt_decode = require('jwt-decode');
const Utility = require('../lib/utils');
const config_dir = require('../../config/dir.json');
const config_test = require("../../config/test.json");

const config_op = require("../../config/op.json");

module.exports = function(app, checkAuthorisation, database) {

Expand Down Expand Up @@ -81,7 +81,7 @@ module.exports = function(app, checkAuthorisation, database) {
*/

// download metadata
app.post("/api/metadata/:type/download", function(req, res) {
app.post(config_op.basepath+"api/metadata/:type/download", function(req, res) {

// check if apikey is correct
let authorisation = checkAuthorisation(req);
Expand Down Expand Up @@ -181,7 +181,7 @@ module.exports = function(app, checkAuthorisation, database) {
});

// execute test for metadata
app.get("/api/metadata/check/:testcase", async function(req, res) {
app.get(config_op.basepath+"api/metadata/check/:testcase", async function(req, res) {

// check if apikey is correct
let authorisation = checkAuthorisation(req);
Expand Down Expand Up @@ -244,7 +244,7 @@ module.exports = function(app, checkAuthorisation, database) {
});

// return last validation from store
app.get("/api/metadata/lastcheck/:testcase", function(req, res) {
app.get(config_op.basepath+"api/metadata/lastcheck/:testcase", function(req, res) {

// check if apikey is correct
let authorisation = checkAuthorisation(req);
Expand Down Expand Up @@ -328,7 +328,7 @@ module.exports = function(app, checkAuthorisation, database) {
*/

// set test for metadata
app.patch("/api/metadata/:testcase/:test", async function(req, res) {
app.patch(config_op.basepath+"api/metadata/:testcase/:test", async function(req, res) {

// check if apikey is correct
let authorisation = checkAuthorisation(req);
Expand Down
10 changes: 5 additions & 5 deletions src/server/api/store.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const fs = require("fs-extra");
const Utility = require("../lib/utils");
const config_dir = require("../../config/dir.json");

const config_op = require("../../config/op.json");
module.exports = function(app, checkAuthorisation, database) {

// list all workspace for user and, maybe, requested store type
//this not saves store to session, use GET /api/store to recover a store instead
app.get("/api/stores", function(req, res) {
app.get(config_op.basepath+"api/stores", function(req, res) {

// check if apikey is correct
if(!checkAuthorisation(req)) {
Expand Down Expand Up @@ -34,7 +34,7 @@ module.exports = function(app, checkAuthorisation, database) {

// recover workspace from store cache
// this RECOVER store from cache and SAVE it to session
app.get("/api/store", function(req, res) {
app.get(config_op.basepath+"api/store", function(req, res) {

// check if apikey is correct
if(!checkAuthorisation(req)) {
Expand Down Expand Up @@ -71,7 +71,7 @@ module.exports = function(app, checkAuthorisation, database) {
});

// save workspace to store cache
app.post("/api/store", function(req, res) {
app.post(config_op.basepath+"api/store", function(req, res) {

// check if apikey is correct
if(!checkAuthorisation(req)) {
Expand All @@ -95,7 +95,7 @@ module.exports = function(app, checkAuthorisation, database) {
});

// delete workspace from store cache
app.delete("/api/store", function(req, res) {
app.delete(config_op.basepath+"api/store", function(req, res) {

// check if apikey is correct
if(!checkAuthorisation(req)) {
Expand Down
Loading