4 Commits

Author SHA1 Message Date
efarooqui
fdee3fa581 Minor changes to media endpoint 2021-06-20 23:11:38 -07:00
efarooqui
f093253d87 Removing unecessary console error 2021-06-09 20:01:20 -07:00
efarooqui
011c667805 Unpacking params for request from media 2021-06-09 01:14:02 -07:00
efarooqui
66d7d42497 Adding media fetch endpoint; working query with hardcoded incident 2021-06-08 18:46:33 -07:00
11 changed files with 56 additions and 9506 deletions

1
.gitignore vendored
View File

@@ -15,4 +15,3 @@ tags.lock
tags.temp
src/config.js
src/local.config.js
src/config.js

View File

@@ -4,12 +4,12 @@ LABEL authors="Lachlan Kermode <lk@forensic-architecture.org>"
# Install app dependencies
COPY package.json /www/package.json
RUN cd /www; npm install
RUN cd /www; yarn
# Copy app source
COPY . /www
WORKDIR /www
RUN npm run build
RUN yarn build
RUN mkdir -p data
# set your port
@@ -17,4 +17,4 @@ ENV PORT 4040
EXPOSE 4040
# start command as per package.json
CMD ["npm", "start"]
CMD ["yarn", "start"]

View File

@@ -59,11 +59,6 @@ Clone the repository to your local:
git clone https://www.github.com/forensic-architecture/datasheet-server
```
Copy [src/example.config.js](src/example.config.js) into `src/config.js` and modify
```
cp src/example.config.js src/config.js
```
Follow the steps in the [configuration](#configuration) section of this
document.

Binary file not shown.

9480
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,7 @@
import { version } from '../../package.json'
import fetch from 'node-fetch'
import { Router } from 'express'
import { getParameterByName } from '../lib/util'
import copy from '../copy/en'
export default ({ config, controller }) => {
@@ -22,6 +24,21 @@ export default ({ config, controller }) => {
})
})
api.get('/media/:code', (req, res) => {
const { code } = req.params
fetch(`${process.env.MEDIA_API_ENDPOINT}/${code}`, {
method: 'get',
headers: {
'Authorization': 'Basic ' + new Buffer(process.env.MEDIA_AUTH_USER + ":" + process.env.MEDIA_AUTH_PWORD).toString("base64")
}
})
.then(response => response.json())
.then(data => res.send(data))
.catch(err => {
res.status(err.status || 404).send({ error: err.message })
});
})
api.get('/update', (req, res) => {
controller
.update()

12
src/config.js Normal file
View File

@@ -0,0 +1,12 @@
import { timemap } from './lib'
export default {
gsheets: [],
xlsx: [
{
name: 'timemap_data',
path: 'data/timemap_data.xlsx',
tabs: timemap.default
}
]
}

View File

@@ -1,19 +0,0 @@
import { timemap } from './lib'
export default {
gsheets: [],
xlsx: [
{
name: 'timemap_data',
path: 'data/timemap_data.xlsx',
tabs: timemap.default
}
],
cors: {
active: false,
corsOptions: { // meaningless unless active=true
origin: 'http://example.com',
optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
}
}
}

View File

@@ -7,14 +7,6 @@ import api from './api'
import dotenv from 'dotenv'
const hbs = require('express-handlebars')
let configJS
try {
configJS = require('./local.config.js').default
} catch (_) {
configJS = require('./config.js').default
}
dotenv.config()
let app = express()
@@ -25,17 +17,13 @@ app.engine('.hbs', hbs({
}))
app.set('view engine', '.hbs')
// enable cross origin requests explicitly in development OR if active in prod
const cors = require('cors')
// enable cross origin requests explicitly in development
if (process.env.NODE_ENV === 'development') {
const cors = require('cors')
console.log('Enabling CORS in development...')
app.use(cors())
} else if (configJS.cors.active === true) {
console.log('Enabling CORS in from config.js in prod...')
app.use(cors(configJS.cors.corsOptions))
}
const config = process.env
initialize(controller => {

View File

@@ -3,7 +3,7 @@ import fetch from 'node-fetch'
import childProcess from 'child_process'
const SERVER_LAUNCH_WAIT_TIME = 10 * 1000
const SERVER_ROOT = ''
const SERVER_ROOT = 'http://localhost:4040'
let serverProc = null
let serverExited = false
function checkStatus (res) {

View File

@@ -8,7 +8,7 @@
<div class="bp-source">{{ source }}</div>
</div>
{{#each urls}}
<div><a target="_blank" href="{{ this }}">{{ this }}</a></div>
<div><a target="_blank" href="http://localhost:4040{{ this }}">{{ this }}</a></div>
{{/each}}
</div>
{{ else }}
@@ -16,7 +16,7 @@
{{/each}}
</div>
<a class="bp-update-container" target="_blank" href="/api/update">
<a class="bp-update-container" target="_blank" href="http://localhost:4040/api/update">
<div class="bp-button">Update</div>
</div>