Skip to content

Commit ff6071e

Browse files
committed
Added Licence. Dockerfile image build. Serve client files from server
1 parent c329e4c commit ff6071e

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

Dockerfile

+15
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,24 @@ RUN npm install
88

99
COPY . .
1010

11+
RUN mkdir -p ./public ./data
12+
1113
# Build server code
1214
RUN npm run build
1315

16+
# Build client code
17+
RUN cd ./client \
18+
&& npm install --production \
19+
&& npm run build \
20+
&& cd .. \
21+
&& mv ./client/build/* ./public
22+
23+
# Clean up src files
24+
RUN rm -rf src/ ./client \
25+
&& npm prune --production
26+
27+
EXPOSE 5000
28+
1429
ENV NODE_ENV=production
1530

1631
CMD ["node", "build/server.js"]

LICENCE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Paweł Malak
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

client/src/containers/Snippet.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Fragment, useContext, useEffect } from 'react';
22
import { useParams, useLocation } from 'react-router-dom';
33
import { SnippetCode } from '../components/Snippets/SnippetCode';
4-
import { Layout, PageHeader, Spinner, Card } from '../components/UI';
4+
import { Layout, PageHeader, Card } from '../components/UI';
55
import { SnippetsContext } from '../store';
66
import { SnippetDetails } from '../components/Snippets/SnippetDetails';
77
import { SnippetDocs } from '../components/Snippets/SnippetDocs';
@@ -25,9 +25,7 @@ export const Snippet = (): JSX.Element => {
2525
return (
2626
<Layout>
2727
{!currentSnippet ? (
28-
<div className='col-12'>
29-
<Spinner />
30-
</div>
28+
<div className='col-12'>Loading...</div>
3129
) : (
3230
<Fragment>
3331
<PageHeader title='' prevDest={from} />

src/server.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { join } from 'path';
12
import dotenv from 'dotenv';
2-
import express from 'express';
3+
import express, { Request, Response } from 'express';
34
import { Logger } from './utils';
45
import { connectDB } from './db';
56
import { errorHandler } from './middleware';
@@ -16,6 +17,12 @@ const PORT = process.env.PORT || 5000;
1617

1718
// App config
1819
app.use(express.json());
20+
app.use(express.static(join(__dirname, '../public')));
21+
22+
// Serve client code
23+
app.get(/^\/(?!api)/, (req: Request, res: Response) => {
24+
res.sendFile(join(__dirname, '../public/index.html'));
25+
});
1926

2027
// Routes
2128
app.use('/api/snippets', snippetRouter);

0 commit comments

Comments
 (0)