From ff6071e5243e2401e9a61b8349d8167322be68cd Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 23 Sep 2021 16:12:02 +0200 Subject: [PATCH] Added Licence. Dockerfile image build. Serve client files from server --- Dockerfile | 15 +++++++++++++++ LICENCE.md | 21 +++++++++++++++++++++ client/src/containers/Snippet.tsx | 6 ++---- src/server.ts | 9 ++++++++- 4 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 LICENCE.md diff --git a/Dockerfile b/Dockerfile index 96dfd97..69bb3fa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,9 +8,24 @@ RUN npm install COPY . . +RUN mkdir -p ./public ./data + # Build server code RUN npm run build +# Build client code +RUN cd ./client \ + && npm install --production \ + && npm run build \ + && cd .. \ + && mv ./client/build/* ./public + +# Clean up src files +RUN rm -rf src/ ./client \ + && npm prune --production + +EXPOSE 5000 + ENV NODE_ENV=production CMD ["node", "build/server.js"] \ No newline at end of file diff --git a/LICENCE.md b/LICENCE.md new file mode 100644 index 0000000..83e91fd --- /dev/null +++ b/LICENCE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Paweł Malak + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/client/src/containers/Snippet.tsx b/client/src/containers/Snippet.tsx index 876dac3..742cad0 100644 --- a/client/src/containers/Snippet.tsx +++ b/client/src/containers/Snippet.tsx @@ -1,7 +1,7 @@ import { Fragment, useContext, useEffect } from 'react'; import { useParams, useLocation } from 'react-router-dom'; import { SnippetCode } from '../components/Snippets/SnippetCode'; -import { Layout, PageHeader, Spinner, Card } from '../components/UI'; +import { Layout, PageHeader, Card } from '../components/UI'; import { SnippetsContext } from '../store'; import { SnippetDetails } from '../components/Snippets/SnippetDetails'; import { SnippetDocs } from '../components/Snippets/SnippetDocs'; @@ -25,9 +25,7 @@ export const Snippet = (): JSX.Element => { return ( {!currentSnippet ? ( -
- -
+
Loading...
) : ( diff --git a/src/server.ts b/src/server.ts index 9734917..4fd9ccc 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,5 +1,6 @@ +import { join } from 'path'; import dotenv from 'dotenv'; -import express from 'express'; +import express, { Request, Response } from 'express'; import { Logger } from './utils'; import { connectDB } from './db'; import { errorHandler } from './middleware'; @@ -16,6 +17,12 @@ const PORT = process.env.PORT || 5000; // App config app.use(express.json()); +app.use(express.static(join(__dirname, '../public'))); + +// Serve client code +app.get(/^\/(?!api)/, (req: Request, res: Response) => { + res.sendFile(join(__dirname, '../public/index.html')); +}); // Routes app.use('/api/snippets', snippetRouter);