diff options
| author | s-ol <s+removethis@s-ol.nu> | 2022-01-13 17:49:50 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2022-01-13 18:00:23 +0000 |
| commit | 19ea970958eea3dc688c631f7ac0ec7818f2689f (patch) | |
| tree | 549bb3ad73d392a1ec50d1a34fd8cf8d7809267a /server | |
| parent | Merge server and client repositories (diff) | |
| download | fedidag-19ea970958eea3dc688c631f7ac0ec7818f2689f.tar.gz fedidag-19ea970958eea3dc688c631f7ac0ec7818f2689f.zip | |
(re)Dockerize!
Diffstat (limited to 'server')
| -rw-r--r-- | server/main.ts | 14 | ||||
| -rw-r--r-- | server/package.json | 1 | ||||
| -rw-r--r-- | server/static/.keep | 0 |
3 files changed, 10 insertions, 5 deletions
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 --- /dev/null +++ b/server/static/.keep |
