diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 87425ae..5de7bef 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,4 +17,6 @@ jobs: - uses: docker/setup-qemu-action@v1 - uses: docker/setup-buildx-action@v1 - name: Build the Docker image - run: docker buildx build -t ghcr.io/v0l/void.cat/app:latest --platform linux/amd64 --push . \ No newline at end of file + run: docker buildx build -t ghcr.io/v0l/void.cat/app:latest --platform linux/amd64 --push . + - name: Build the NoSPA Docker image + run: docker buildx build -t ghcr.io/v0l/void.cat/api:latest -f nospa.dockerfile --platform linux/amd64 --push . \ No newline at end of file diff --git a/VoidCat/Program.cs b/VoidCat/Program.cs index 360ca1e..03d5d6b 100644 --- a/VoidCat/Program.cs +++ b/VoidCat/Program.cs @@ -107,7 +107,9 @@ foreach (var migration in migrations) await migration.Migrate(); } +#if HostSPA app.UseStaticFiles(); +#endif app.UseRouting(); app.UseAuthentication(); @@ -117,7 +119,9 @@ app.UseEndpoints(ep => { ep.MapControllers(); ep.MapMetrics(); +#if HostSPA ep.MapFallbackToFile("index.html"); +#endif }); app.Run(); diff --git a/VoidCat/VoidCat.csproj b/VoidCat/VoidCat.csproj index d256e28..b72132c 100644 --- a/VoidCat/VoidCat.csproj +++ b/VoidCat/VoidCat.csproj @@ -4,10 +4,11 @@ net6.0 enable enable - 126065b9-67d3-4d98-9bad-82f359a7e313 Linux spa\ $(DefaultItemExcludes);$(SpaRoot)node_modules\** + True + $(DefineConstants);HostSPA @@ -27,6 +28,9 @@ Dockerfile + + nospa.dockerfile + @@ -41,12 +45,12 @@ - + - + <_CopyItems Include="$(SpaRoot)build\**\*.*" /> diff --git a/VoidCat/spa/package.json b/VoidCat/spa/package.json index 5b9dde1..5ddf725 100644 --- a/VoidCat/spa/package.json +++ b/VoidCat/spa/package.json @@ -7,6 +7,7 @@ "@reduxjs/toolkit": "^1.7.2", "feather-icons-react": "^0.5.0", "moment": "^2.29.1", + "preval.macro": "^5.0.0", "qrcode.react": "^1.0.1", "react": "^17.0.2", "react-dom": "^17.0.2", diff --git a/VoidCat/spa/src/Api.js b/VoidCat/spa/src/Api.js index 3de733e..5cfeb6a 100644 --- a/VoidCat/spa/src/Api.js +++ b/VoidCat/spa/src/Api.js @@ -1,4 +1,7 @@ import {useSelector} from "react-redux"; +import preval from "preval.macro"; + +const ApiHost = preval`module.exports = process.env.API_HOST || '';`; export function useApi() { const auth = useSelector(state => state.login.jwt); @@ -14,7 +17,7 @@ export function useApi() { headers["Content-Type"] = "application/json"; } - return await fetch(url, { + return await fetch(`${ApiHost}${url}`, { method, headers, body: body ? JSON.stringify(body) : undefined diff --git a/VoidCat/spa/yarn.lock b/VoidCat/spa/yarn.lock index fc833c1..64bf4f6 100644 --- a/VoidCat/spa/yarn.lock +++ b/VoidCat/spa/yarn.lock @@ -1511,7 +1511,7 @@ resolved "https://registry.yarnpkg.com/@trysound/sax/-/sax-0.2.0.tgz#cccaab758af56761eb7bf37af6f03f326dd798ad" integrity sha512-L7z9BgrNEcYyUYtF+HaEfiS5ebkh9jXqbszz7pC0hRBPaatV0XjSD3+eHrpqFemQfgwiFF0QPIarnIihIDn7OA== -"@types/babel__core@^7.0.0", "@types/babel__core@^7.1.14": +"@types/babel__core@^7.0.0", "@types/babel__core@^7.1.12", "@types/babel__core@^7.1.14": version "7.1.18" resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.18.tgz#1a29abcc411a9c05e2094c98f9a1b7da6cdf49f8" integrity sha512-S7unDjm/C7z2A2R9NzfKCK1I+BAALDtxEmsJBwlB3EzNfb929ykjL++1CK9LO++EIp2fQrC8O+BwjKvz6UeDyQ== @@ -2374,7 +2374,7 @@ babel-plugin-jest-hoist@^27.4.0: "@types/babel__core" "^7.0.0" "@types/babel__traverse" "^7.0.6" -babel-plugin-macros@^3.1.0: +babel-plugin-macros@^3.0.1, babel-plugin-macros@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/babel-plugin-macros/-/babel-plugin-macros-3.1.0.tgz#9ef6dc74deb934b4db344dc973ee851d148c50c1" integrity sha512-Cg7TFGpIr01vOQNODXOOaGz2NpCU5gl8x1qJFbb6hbZxR7XrcE2vtbAsTAbJ7/xwJtUuJEw8K8Zr/AE0LHlesg== @@ -2412,6 +2412,16 @@ babel-plugin-polyfill-regenerator@^0.3.0: dependencies: "@babel/helper-define-polyfill-provider" "^0.3.1" +babel-plugin-preval@^5.0.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/babel-plugin-preval/-/babel-plugin-preval-5.1.0.tgz#6efb89bf6b97af592cd1400c6df49c0e9e6ab027" + integrity sha512-G5R+xmo5LS41A4UyZjOjV0mp9AvkuCyUOAJ6TOv/jTZS+VKh7L7HUDRcCSOb0YCM/u0fFarh7Diz0wjY8rFNFg== + dependencies: + "@babel/runtime" "^7.12.5" + "@types/babel__core" "^7.1.12" + babel-plugin-macros "^3.0.1" + require-from-string "^2.0.2" + babel-plugin-transform-react-remove-prop-types@^0.4.24: version "0.4.24" resolved "https://registry.yarnpkg.com/babel-plugin-transform-react-remove-prop-types/-/babel-plugin-transform-react-remove-prop-types-0.4.24.tgz#f2edaf9b4c6a5fbe5c1d678bfb531078c1555f3a" @@ -6699,6 +6709,13 @@ pretty-format@^27.4.6: ansi-styles "^5.0.0" react-is "^17.0.1" +preval.macro@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/preval.macro/-/preval.macro-5.0.0.tgz#bb9e0e0cd06aee094dd84eed89851b5a7337cc2f" + integrity sha512-+OZRqZYx1pjZ7H5Jis8bPFXkiT7lwA46UzAT4IjuzFVKwkJK+TwIx1TCqrqNCf8U3e5O12mEJEz1BXslkCLWfQ== + dependencies: + babel-plugin-preval "^5.0.0" + process-nextick-args@~2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2" diff --git a/nospa.dockerfile b/nospa.dockerfile new file mode 100644 index 0000000..ce2ef54 --- /dev/null +++ b/nospa.dockerfile @@ -0,0 +1,14 @@ +# syntax=docker/dockerfile:1 +FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env +WORKDIR /app + +# Copy everything else and build +COPY VoidCat . +RUN rm -rf appsettings.*.json +RUN dotnet publish -c Release -o out -p:HostSPA=Flase VoidCat.csproj + +# Build runtime image +FROM mcr.microsoft.com/dotnet/aspnet:6.0 +WORKDIR /app +COPY --from=build-env /app/out . +ENTRYPOINT ["dotnet", "VoidCat.dll"] \ No newline at end of file