Added Licence. Dockerfile image build. Serve client files from server

This commit is contained in:
unknown
2021-09-23 16:12:02 +02:00
parent c329e4c636
commit ff6071e524
4 changed files with 46 additions and 5 deletions

View File

@@ -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"]

21
LICENCE.md Normal file
View File

@@ -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.

View File

@@ -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 (
<Layout>
{!currentSnippet ? (
<div className='col-12'>
<Spinner />
</div>
<div className='col-12'>Loading...</div>
) : (
<Fragment>
<PageHeader title='' prevDest={from} />

View File

@@ -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);