Browse Source

include proxying for the backend in the server

unoptim
DashEightMate 1 year ago
parent
commit
8101eddb21
  1. 1
      .eslintignore
  2. 2
      docker/Dockerfile
  3. 1
      package.json
  4. 7
      server/package.json
  5. 16
      server/src/index.ts
  6. 2
      server/tsconfig.json
  7. 60
      server/yarn.lock

1
.eslintignore

@ -5,3 +5,4 @@ src/translations
jest.config.js
vite.config.ts
git-version.ts
server/

2
docker/Dockerfile

@ -16,4 +16,4 @@ VOLUME /app/dist
WORKDIR /app/server
EXPOSE 4444
CMD ["node", "--loader", "ts-node/esm", "src/index.ts"]
CMD ["node", "src/index.ts"]

1
package.json

@ -7,6 +7,7 @@
"scripts": {
"api-test": "jest src/api_tests/api.spec.ts",
"build": "node generate_translations.js && node generate_git_version.js && tsc --noEmit && NODE_ENV=production vite build --base=/static/ --sourcemap",
"build-dev": "node generate_translations.js && node generate_git_version.js && tsc --noEmit && NODE_ENV=development vite build --base=/static/ --sourcemap",
"lint": "tsc --noEmit && eslint --quiet --report-unused-disable-directives --ext .js,.ts,.tsx src",
"start": "node generate_translations.js && vite --port 4444 --open",
"storybook": "start-storybook -p 9009",

7
server/package.json

@ -6,13 +6,15 @@
"license": "AGPL-3.0",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon src/index.ts"
"start": "NODE_ENV=development nodemon src/index.ts",
"lint": "eslint --quiet --report-unused-disable-directives --ext .js,.ts,.tsx src"
},
"keywords": [],
"author": "",
"type": "module",
"type": "commonjs",
"devDependencies": {
"@types/express": "^4.17.12",
"@types/express-http-proxy": "^1.6.1",
"@types/node": "^15.14.0",
"@typescript-eslint/eslint-plugin": "^4.28.1",
"@typescript-eslint/parser": "^4.28.1",
@ -24,6 +26,7 @@
},
"dependencies": {
"express": "^4.17.1",
"http-proxy-middleware": "^2.0.1",
"ts-node": "^10.0.0"
}
}

16
server/src/index.ts

@ -1,4 +1,15 @@
/*
An express server to host the frontend.
Before you use it, you have to build the frontend using `yarn build` in the root of the repository.
To run this for development, use `yarn run` in the /server directory. To run this for production, check the dockerfile in /docker.
This isn't reccomended for frontend development because you have to rebuild the frontend to propogate changes.
For an auto-reloading development server for the frontend, run `yarn run` in the root of the repository.
*/
import express from 'express';
import { createProxyMiddleware } from 'http-proxy-middleware';
import path from 'path';
const app = express();
@ -14,6 +25,11 @@ app.get(SERVICED_ROUTES, (req, res) => {
res.sendFile(path.resolve("../dist/index.html"));
});
//In a development environment (i.e. without nginx proxying) proxy backend requests to the backend
if (process.env.NODE_ENV === "development") {
app.use(['/api', '/pictrs'], createProxyMiddleware('http://localhost:8536'));
}
app.listen(PORT, () => {
console.log(`Frontend server running on port ${PORT}`)
})

2
server/tsconfig.json

@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"module": "commonjs",
"rootDir": "./",
"outDir": "./build",
"esModuleInterop": true,

60
server/yarn.lock

@ -106,6 +106,13 @@
dependencies:
"@types/node" "*"
"@types/[email protected]^1.6.1":
version "1.6.1"
resolved "https://registry.yarnpkg.com/@types/express-http-proxy/-/express-http-proxy-1.6.1.tgz#b505ecdf51bf6d5b361fd8bfa777baabe4427a44"
integrity sha512-FjuKVtGaT3ccHD7uFr7vKDsn3shEEc/Upo2YnVsTfoDPuUbCV/GIsinG7gbrkzcIYELqh+8hYmn/rEfqMQA/9g==
dependencies:
"@types/express" "*"
"@types/[email protected]^4.17.18":
version "4.17.22"
resolved "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.22.tgz"
@ -115,7 +122,7 @@
"@types/qs" "*"
"@types/range-parser" "*"
"@types/[email protected]^4.17.12":
"@types/[email protected]*", "@types/[email protected]^4.17.12":
version "4.17.12"
resolved "https://registry.npmjs.org/@types/express/-/express-4.17.12.tgz"
integrity sha512-pTYas6FrP15B1Oa0bkN5tQMNqOcVXa9j4FTFtO8DWI9kppKib+6NJtfTOOLcwxuuYvcX2+dVG6et1SxW/Kc17Q==
@ -125,6 +132,13 @@
"@types/qs" "*"
"@types/serve-static" "*"
"@types/[email protected]^1.17.5":
version "1.17.6"
resolved "https://registry.yarnpkg.com/@types/http-proxy/-/http-proxy-1.17.6.tgz#62dc3fade227d6ac2862c8f19ee0da9da9fd8616"
integrity sha512-+qsjqR75S/ib0ig0R9WN+CDoZeOBU6F2XLewgC4KVgdXiNHiKKHFEMRHOrs5PbYE97D5vataw5wPj4KLYfUkuQ==
dependencies:
"@types/node" "*"
"@types/[email protected]^7.0.7":
version "7.0.7"
resolved "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.7.tgz"
@ -967,6 +981,11 @@ [email protected]~1.8.1:
resolved "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz"
integrity sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=
[email protected]^4.0.0:
version "4.0.7"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f"
integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==
[email protected]^4.17.1:
version "4.17.1"
resolved "https://registry.npmjs.org/express/-/express-4.17.1.tgz"
@ -1083,6 +1102,11 @@ [email protected]^3.1.0:
resolved "https://registry.npmjs.org/flatted/-/flatted-3.2.0.tgz"
integrity sha512-XprP7lDrVT+kE2c2YlfiV+IfS9zxukiIOvNamPNsImNhXadSsQEbosItdL9bUQlCZXR13SvPk20BjWSWLA7m4A==
[email protected]^1.0.0:
version "1.14.1"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.1.tgz#d9114ded0a1cfdd334e164e6662ad02bfd91ff43"
integrity sha512-HWqDgT7ZEkqRzBvc2s64vSZ/hfOceEol3ac/7tKwzuvEyWx3/4UegXh5oBOIotkGsObyk3xznnSRVADBgWSQVg==
[email protected]:
version "0.2.0"
resolved "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz"
@ -1256,6 +1280,26 @@ [email protected], [email protected]~1.7.2:
statuses ">= 1.5.0 < 2"
toidentifier "1.0.0"
[email protected]^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/http-proxy-middleware/-/http-proxy-middleware-2.0.1.tgz#7ef3417a479fb7666a571e09966c66a39bd2c15f"
integrity sha512-cfaXRVoZxSed/BmkA7SwBVNI9Kj7HFltaE5rqYOub5kWzWZ+gofV2koVN1j2rMW7pEfSSlCHGJ31xmuyFyfLOg==
dependencies:
"@types/http-proxy" "^1.17.5"
http-proxy "^1.18.1"
is-glob "^4.0.1"
is-plain-obj "^3.0.0"
micromatch "^4.0.2"
[email protected]^1.18.1:
version "1.18.1"
resolved "https://registry.yarnpkg.com/http-proxy/-/http-proxy-1.18.1.tgz#401541f0534884bbf95260334e72f88ee3976549"
integrity sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==
dependencies:
eventemitter3 "^4.0.0"
follow-redirects "^1.0.0"
requires-port "^1.0.0"
[email protected]:
version "0.4.24"
resolved "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz"
@ -1427,6 +1471,11 @@ [email protected]^3.0.1:
resolved "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.3.tgz"
integrity sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==
[email protected]^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-3.0.0.tgz#af6f2ea14ac5a646183a5bbdb5baabbc156ad9d7"
integrity sha512-gwsOE28k+23GP1B6vFl1oVh/WOzmawBrKwo5Ev6wMKzPkaXaCDIQKzLnvsA42DRlbVTWorkgTKIviAKCWkfUwA==
[email protected]^1.1.3:
version "1.1.3"
resolved "https://registry.npmjs.org/is-regex/-/is-regex-1.1.3.tgz"
@ -1611,7 +1660,7 @@ [email protected]~1.1.2:
resolved "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz"
integrity sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=
[email protected]^4.0.4:
[email protected]^4.0.2, [email protected]^4.0.4:
version "4.0.4"
resolved "https://registry.npmjs.org/micromatch/-/micromatch-4.0.4.tgz"
integrity sha512-pRmzw/XUcwXGpD9aI9q/0XOwLNygjETJ8y0ao0wdqprrzDa4YnxLcz7fQRZr8voh8V10kGhABbNcHVk5wHgWwg==
@ -2036,6 +2085,11 @@ [email protected]^2.0.2:
resolved "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz"
integrity sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==
[email protected]^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=
[email protected]^4.0.0:
version "4.0.0"
resolved "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz"
@ -2348,7 +2402,7 @@ [email protected]^3.1.0:
[email protected]^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.0.0.tgz#05f10b9a716b0b624129ad44f0ea05dac84ba3be"
resolved "https://registry.npmjs.org/ts-node/-/ts-node-10.0.0.tgz"
integrity sha512-ROWeOIUvfFbPZkoDis0L/55Fk+6gFQNZwwKPLinacRl6tsxstTF1DbAcLKkovwnpKMVvOMHP1TIbnwXwtLg1gg==
dependencies:
"@tsconfig/node10" "^1.0.7"

Loading…
Cancel
Save