Skip to content
Snippets Groups Projects
Commit 83ee4e44 authored by esikkala's avatar esikkala
Browse files

Add separate API url

parent 34f32c90
No related branches found
No related tags found
No related merge requests found
...@@ -14,8 +14,8 @@ import { ...@@ -14,8 +14,8 @@ import {
} from '../actions'; } from '../actions';
const apiUrl = (process.env.NODE_ENV === 'development') const apiUrl = (process.env.NODE_ENV === 'development')
? 'http://localhost:3001' ? 'http://localhost:3001/api/'
: location.href; : `${location.href}/api/`;
const getManuscripts = (action$, state$) => action$.pipe( const getManuscripts = (action$, state$) => action$.pipe(
ofType(FETCH_MANUSCRIPTS), ofType(FETCH_MANUSCRIPTS),
...@@ -33,7 +33,7 @@ const getManuscripts = (action$, state$) => action$.pipe( ...@@ -33,7 +33,7 @@ const getManuscripts = (action$, state$) => action$.pipe(
if (activeFilters) { if (activeFilters) {
params.filters = JSON.stringify(filters); params.filters = JSON.stringify(filters);
} }
const searchUrl = apiUrl + '/manuscripts'; const searchUrl = apiUrl + 'manuscripts';
const requestUrl = `${searchUrl}?${stringify(params)}`; const requestUrl = `${searchUrl}?${stringify(params)}`;
return ajax.getJSON(requestUrl).pipe( return ajax.getJSON(requestUrl).pipe(
map(data => updateManuscripts({ data })) map(data => updateManuscripts({ data }))
...@@ -44,7 +44,7 @@ const getManuscripts = (action$, state$) => action$.pipe( ...@@ -44,7 +44,7 @@ const getManuscripts = (action$, state$) => action$.pipe(
const getPlaces = action$ => action$.pipe( const getPlaces = action$ => action$.pipe(
ofType(FETCH_PLACES), ofType(FETCH_PLACES),
mergeMap(action => { mergeMap(action => {
const searchUrl = apiUrl + '/places'; const searchUrl = apiUrl + 'places';
const requestUrl = `${searchUrl}?variant=${action.variant}`; const requestUrl = `${searchUrl}?variant=${action.variant}`;
return ajax.getJSON(requestUrl).pipe( return ajax.getJSON(requestUrl).pipe(
map(response => updatePlaces({ places: response })) map(response => updatePlaces({ places: response }))
...@@ -55,7 +55,7 @@ const getPlaces = action$ => action$.pipe( ...@@ -55,7 +55,7 @@ const getPlaces = action$ => action$.pipe(
const getPlace = action$ => action$.pipe( const getPlace = action$ => action$.pipe(
ofType(FETCH_PLACE), ofType(FETCH_PLACE),
mergeMap(action => { mergeMap(action => {
const searchUrl = apiUrl + '/places'; const searchUrl = apiUrl + 'places';
const requestUrl = `${searchUrl}/${encodeURIComponent(action.placeId)}`; const requestUrl = `${searchUrl}/${encodeURIComponent(action.placeId)}`;
return ajax.getJSON(requestUrl).pipe( return ajax.getJSON(requestUrl).pipe(
map(response => updatePlace({ place: response })) map(response => updatePlace({ place: response }))
...@@ -79,7 +79,7 @@ const getFacet = (action$, state$) => action$.pipe( ...@@ -79,7 +79,7 @@ const getFacet = (action$, state$) => action$.pipe(
if (activeFilters) { if (activeFilters) {
params.filters = JSON.stringify(filters); params.filters = JSON.stringify(filters);
} }
const searchUrl = apiUrl + '/facets'; const searchUrl = apiUrl + 'facets';
const requestUrl = `${searchUrl}?${stringify(params)}`; const requestUrl = `${searchUrl}?${stringify(params)}`;
return ajax.getJSON(requestUrl).pipe( return ajax.getJSON(requestUrl).pipe(
map(response => updateFacet({ facetValues: response })) map(response => updateFacet({ facetValues: response }))
......
import express from 'express'; import express from 'express';
const path = require('path'); const path = require('path');
import bodyParser from 'body-parser'; import bodyParser from 'body-parser';
import { import {
getManuscripts, getManuscripts,
getPlaces, getPlaces,
...@@ -10,6 +9,7 @@ import { ...@@ -10,6 +9,7 @@ import {
} from './sparql/Manuscripts'; } from './sparql/Manuscripts';
const DEFAULT_PORT = 3001; const DEFAULT_PORT = 3001;
const app = express(); const app = express();
const apiPath = '/api';
app.set('port', process.env.PORT || DEFAULT_PORT); app.set('port', process.env.PORT || DEFAULT_PORT);
app.use(bodyParser.json()); app.use(bodyParser.json());
...@@ -24,7 +24,7 @@ app.use(function(req, res, next) { ...@@ -24,7 +24,7 @@ app.use(function(req, res, next) {
// Serve the static files from the React app // Serve the static files from the React app
app.use(express.static(path.join(__dirname, './../public/'))); app.use(express.static(path.join(__dirname, './../public/')));
app.get('/manuscripts', (req, res) => { app.get(`${apiPath}/manuscripts`, (req, res) => {
const page = parseInt(req.query.page) || 0; const page = parseInt(req.query.page) || 0;
const filters = req.query.filters == null ? null : JSON.parse(req.query.filters); const filters = req.query.filters == null ? null : JSON.parse(req.query.filters);
const pagesize = 5; const pagesize = 5;
...@@ -39,7 +39,7 @@ app.get('/manuscripts', (req, res) => { ...@@ -39,7 +39,7 @@ app.get('/manuscripts', (req, res) => {
}); });
}); });
app.get('/places/:placeId?', (req, res) => { app.get(`${apiPath}/places/:placeId?`, (req, res) => {
if (req.params.placeId) { if (req.params.placeId) {
return getPlace(req.params.placeId).then(data => { return getPlace(req.params.placeId).then(data => {
res.json(data[0]); res.json(data[0]);
...@@ -61,7 +61,7 @@ app.get('/places/:placeId?', (req, res) => { ...@@ -61,7 +61,7 @@ app.get('/places/:placeId?', (req, res) => {
} }
}); });
app.get('/facets', (req, res) => { app.get(`${apiPath}/facets`, (req, res) => {
const filters = req.query.filters == null ? null : JSON.parse(req.query.filters); const filters = req.query.filters == null ? null : JSON.parse(req.query.filters);
// console.log(filters) // console.log(filters)
return getFacets(filters).then((data) => { return getFacets(filters).then((data) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment