Add docker-compose with proxy

This commit is contained in:
viktorstrate
2019-08-30 15:43:24 +02:00
parent eb653b66c3
commit 44e8a0481e
7 changed files with 115 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
import { ApolloServer } from 'apollo-server-express'
import express from 'express'
import express, { Router } from 'express'
import bodyParser from 'body-parser'
import cors from 'cors'
import { v1 as neo4j } from 'neo4j-driver'
@@ -8,6 +8,7 @@ import PhotoScanner from './scanner/Scanner'
import _ from 'lodash'
import config from './config'
import gql from 'graphql-tag'
import path from 'path'
import { getUserFromToken, getTokenFromBearer } from './token'
@@ -41,7 +42,8 @@ app.use((req, res, next) => {
setInterval(scanner.scanAll, 1000 * 60 * 60 * 4)
// Specify port and path for GraphQL endpoint
const graphPath = '/graphql'
const graphPath = new URL(path.join(config.host.toString(), '/graphql'))
.pathname
app.use(graphPath, (req, res, next) => {
if (req.body.query) {
@@ -102,6 +104,7 @@ const server = new ApolloServer({
introspection: true,
playground: !process.env.PRODUCTION,
subscriptions: {
path: graphPath,
onConnect: async (connectionParams, webSocket) => {
const token = getTokenFromBearer(connectionParams.Authorization)
const user = await getUserFromToken(token, driver)
@@ -115,12 +118,15 @@ const server = new ApolloServer({
})
server.applyMiddleware({ app, path: graphPath })
const router = new Router()
import loadImageRoutes from './routes/images'
import loadDownloadRoutes from './routes/downloads'
loadImageRoutes(app)
loadDownloadRoutes(app)
loadImageRoutes(router)
loadDownloadRoutes(router)
app.use(config.host.pathname, router)
const httpServer = http.createServer(app)
server.installSubscriptionHandlers(httpServer)

View File

@@ -1,4 +1,5 @@
import { cypherQuery } from 'neo4j-graphql-js'
import path from 'path'
import config from '../config'
function injectAt(query, index, injection) {
@@ -126,7 +127,8 @@ const Query = {
const urlResolve = {
url(root, args, ctx, info) {
let url = new URL(root.url, config.host)
let url = new URL(path.join(config.host.href, root.url))
if (ctx.shareToken) url.search = `?token=${ctx.shareToken}`
return url.href
},

View File

@@ -18,9 +18,9 @@ async function sendDownload(req, res) {
throw new RequestError(404, 'Image could not be found')
}
const loadDownloadRoutes = app => {
app.use('/download/:id/:image', getImageFromRequest)
app.use('/download/:id/:image', sendDownload)
const loadDownloadRoutes = router => {
router.use('/download/:id/:image', getImageFromRequest)
router.use('/download/:id/:image', sendDownload)
}
export default loadDownloadRoutes

View File

@@ -177,9 +177,9 @@ async function verifyShareToken({ shareToken, id, driver }) {
}
}
function loadImageRoutes(app) {
app.use('/images/:id/:image', getImageFromRequest)
app.use('/images/:id/:image', sendImage)
function loadImageRoutes(router) {
router.use('/images/:id/:image', getImageFromRequest)
router.use('/images/:id/:image', sendImage)
}
export default loadImageRoutes