From 19ea970958eea3dc688c631f7ac0ec7818f2689f Mon Sep 17 00:00:00 2001 From: s-ol Date: Thu, 13 Jan 2022 18:49:50 +0100 Subject: (re)Dockerize! --- server/main.ts | 14 +++++++++----- server/package.json | 1 + server/static/.keep | 0 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 server/static/.keep (limited to 'server') diff --git a/server/main.ts b/server/main.ts index 43ab64a..7584d86 100644 --- a/server/main.ts +++ b/server/main.ts @@ -1,4 +1,4 @@ -import { URLSearchParams } from "url"; +import { URL, URLSearchParams } from "url"; import express from "express"; import cors from "cors"; import fetch from "node-fetch"; @@ -10,7 +10,7 @@ import { wrap } from "./async"; const PORT = process.env.PORT ? +process.env.PORT : 3000; const DISCDAG_URL = process.env.DISCDAG_URL ?? 'http://solipsys.co.uk/cgi-bin/DiscDAG.py'; const PUBLIC_URL = process.env.PUBLIC_URL ?? 'http://localhost:3000'; -const DEBUG = process.env.NODE_ENV !== 'production' || PUBLIC_URL.indexOf('localhost') > -1; +const DEBUG = process.env.NODE_ENV ? process.env.NODE_ENV !== 'production' : PUBLIC_URL.indexOf('localhost') > -1; const app = express(); @@ -19,6 +19,9 @@ if (DEBUG) { origin: 'http://localhost:8080', credentials: true, })); + app.use(express.static('../client/dist/')); +} else { + app.use(express.static('static')); } app.use(express.json()); app.use(cookieParser()); @@ -200,11 +203,12 @@ const discdag = express() app.use('/discdag', discdag); app.get(/\/remote\/.*/, wrap(async ($req, $res) => { - const { origin } = $req.headers; + const { origin, referer } = $req.headers; const url = $req.url.match('^/remote/(.*)')![1]; - if (!DEBUG && origin !== PUBLIC_URL) { - return $res.status(403).end(); + if (!DEBUG) { + const org = origin ?? new URL(referer!).origin; + if (org !== PUBLIC_URL) return $res.status(403).end(); } const res = await fetch(url, { diff --git a/server/package.json b/server/package.json index b51d743..0435ee3 100644 --- a/server/package.json +++ b/server/package.json @@ -1,6 +1,7 @@ { "name": "fedidag-server", "version": "0.0.1", + "main": "main.js", "scripts": { "start": "ts-node-dev ./main.ts", "build": "tsc" diff --git a/server/static/.keep b/server/static/.keep new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3