From 15b8e321735cccb5ccac0fd7865b24bc33d7cc0f Mon Sep 17 00:00:00 2001 From: Jack Buehner Date: Sun, 7 Apr 2024 01:39:39 -0400 Subject: [PATCH] feat!: switch to stub server --- apps/server/package.json | 3 ++- apps/server/src/index.old.ts | 10 ++++++++++ apps/server/src/index.ts | 30 ++++++++++++++++++++---------- 3 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 apps/server/src/index.old.ts diff --git a/apps/server/package.json b/apps/server/package.json index d0d47893..99f72e23 100644 --- a/apps/server/package.json +++ b/apps/server/package.json @@ -16,7 +16,8 @@ "inspect-prod": "npm run dev:prepare && tsc --build && cross-env PORT=${PORT:=3000} NODE_OPTIONS=${SERVER_NODE_OPTIONS} APP_URL=${APP_URL:=https://cristata.app} AUTH_APP_URL=${AUTH_APP_URL:=https://auth.cristata.app} NODE_ENV=development node --inspect dist/index.js", "build": "tsc --build && tsc --declaration && cross-env NODE_ENV=production npm run lint", "check": "tsc && npm run lint", - "test": "jest", + "test": "", + "test.old": "jest", "lint": "eslint . --ext .js,.jsx,.ts,.tsx", "clean": "rm -rf dist", "postinstall": "patch-package --error-on-fail false", diff --git a/apps/server/src/index.old.ts b/apps/server/src/index.old.ts new file mode 100644 index 00000000..9c120ae4 --- /dev/null +++ b/apps/server/src/index.old.ts @@ -0,0 +1,10 @@ +import CristataServer from './Cristata'; + +const server = new CristataServer(); +server.start(); + +// log the stack of warnings so we can figure out from where the warning is coming +process.on('warning', (error) => { + console.warn(error); + console.warn(error.stack); +}); diff --git a/apps/server/src/index.ts b/apps/server/src/index.ts index 9c120ae4..fa149a61 100644 --- a/apps/server/src/index.ts +++ b/apps/server/src/index.ts @@ -1,10 +1,20 @@ -import CristataServer from './Cristata'; - -const server = new CristataServer(); -server.start(); - -// log the stack of warnings so we can figure out from where the warning is coming -process.on('warning', (error) => { - console.warn(error); - console.warn(error.stack); -}); +import cors from 'cors'; +import express from 'express'; + +if (!process.env.PORT) throw new Error('PORT not defined in env'); + +// create express app +const app = express(); + +// enable CORS for the app +app.use(cors({ origin: true })); + +// always redirect troop-370 file urls since they no longer use Cristata +// but they want the old filestore urls to still work +app.get('/filestore/troop-370/:_id', (req, res) => { + res.redirect(301, `https://troop370atlanta.org/cristata-filestore/${req.params._id}`); +}); + +app.listen(process.env.PORT, () => { + console.log(`Cristata server stub listening on port ${process.env.PORT}!`); +});