mirror of
https://github.com/pawelmalak/snippet-box.git
synced 2025-12-21 13:23:05 +01:00
Added Licence. Dockerfile image build. Serve client files from server
This commit is contained in:
15
Dockerfile
15
Dockerfile
@@ -8,9 +8,24 @@ RUN npm install
|
|||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
RUN mkdir -p ./public ./data
|
||||||
|
|
||||||
# Build server code
|
# Build server code
|
||||||
RUN npm run build
|
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
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
CMD ["node", "build/server.js"]
|
CMD ["node", "build/server.js"]
|
||||||
21
LICENCE.md
Normal file
21
LICENCE.md
Normal 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.
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Fragment, useContext, useEffect } from 'react';
|
import { Fragment, useContext, useEffect } from 'react';
|
||||||
import { useParams, useLocation } from 'react-router-dom';
|
import { useParams, useLocation } from 'react-router-dom';
|
||||||
import { SnippetCode } from '../components/Snippets/SnippetCode';
|
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 { SnippetsContext } from '../store';
|
||||||
import { SnippetDetails } from '../components/Snippets/SnippetDetails';
|
import { SnippetDetails } from '../components/Snippets/SnippetDetails';
|
||||||
import { SnippetDocs } from '../components/Snippets/SnippetDocs';
|
import { SnippetDocs } from '../components/Snippets/SnippetDocs';
|
||||||
@@ -25,9 +25,7 @@ export const Snippet = (): JSX.Element => {
|
|||||||
return (
|
return (
|
||||||
<Layout>
|
<Layout>
|
||||||
{!currentSnippet ? (
|
{!currentSnippet ? (
|
||||||
<div className='col-12'>
|
<div className='col-12'>Loading...</div>
|
||||||
<Spinner />
|
|
||||||
</div>
|
|
||||||
) : (
|
) : (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<PageHeader title='' prevDest={from} />
|
<PageHeader title='' prevDest={from} />
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
import { join } from 'path';
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
import express from 'express';
|
import express, { Request, Response } from 'express';
|
||||||
import { Logger } from './utils';
|
import { Logger } from './utils';
|
||||||
import { connectDB } from './db';
|
import { connectDB } from './db';
|
||||||
import { errorHandler } from './middleware';
|
import { errorHandler } from './middleware';
|
||||||
@@ -16,6 +17,12 @@ const PORT = process.env.PORT || 5000;
|
|||||||
|
|
||||||
// App config
|
// App config
|
||||||
app.use(express.json());
|
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
|
// Routes
|
||||||
app.use('/api/snippets', snippetRouter);
|
app.use('/api/snippets', snippetRouter);
|
||||||
|
|||||||
Reference in New Issue
Block a user