Skip to content

Commit 21c49cb

Browse files
rootclintonwoo
root
authored andcommitted
Initial commit
Site is working without JS Working well More Cleaned up Clean up prettier jest fix tests reverted lru cache revert lru cache Comment expanding works README more Added page title meta added demo link Fixed user and made cache more fresh Add files via upload Update README.md Update README.md Update README.md Update README.md Update README.md remove readme more Initial commit Site is working without JS Working well More Cleaned up Clean up prettier jest fix tests reverted lru cache revert lru cache Comment expanding works README more Added page title meta added demo link Fixed user and made cache more fresh Add files via upload Update README.md Update README.md Update README.md Update README.md Update README.md remove readme more Initial commit Site is working without JS Working well More Cleaned up Clean up prettier jest fix tests reverted lru cache revert lru cache Comment expanding works README more Added page title meta added demo link Fixed user and made cache more fresh Add files via upload Update README.md Update README.md Update README.md Update README.md Update README.md remove readme more fixed tests fixed tests Initial commit Site is working without JS Working well More Cleaned up Clean up prettier jest fix tests reverted lru cache revert lru cache Comment expanding works README more Added page title meta added demo link Fixed user and made cache more fresh Add files via upload Update README.md Update README.md Update README.md Update README.md Update README.md remove readme more fixed tests fixed tests Initial commit Site is working without JS Working well More Cleaned up Clean up prettier jest fix tests reverted lru cache revert lru cache Comment expanding works README more Added page title meta added demo link Fixed user and made cache more fresh Add files via upload Update README.md Update README.md Update README.md Update README.md Update README.md remove readme more Initial commit Site is working without JS Working well More Cleaned up Clean up prettier jest fix tests reverted lru cache revert lru cache Comment expanding works README more Added page title meta added demo link Fixed user and made cache more fresh Add files via upload Update README.md Update README.md Update README.md Update README.md Update README.md remove readme more Initial commit Site is working without JS Working well More Cleaned up Clean up prettier jest fix tests reverted lru cache revert lru cache Comment expanding works README more Added page title meta added demo link Fixed user and made cache more fresh Add files via upload Update README.md Update README.md Update README.md Update README.md Update README.md remove readme more fixed tests fixed tests Initial commit Site is working without JS Working well More Cleaned up Clean up prettier jest fix tests reverted lru cache revert lru cache Comment expanding works README more Added page title meta added demo link Fixed user and made cache more fresh Add files via upload Update README.md Update README.md Update README.md Update README.md Update README.md remove readme more fixed tests fixed tests mocks mocks space in jest config file prettier
0 parents  commit 21c49cb

File tree

172 files changed

+30810
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

172 files changed

+30810
-0
lines changed

.dockerignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.git
2+
.next
3+
build
4+
dist
5+
docs
6+
node_modules
7+
npm-debug.log
8+
public/build

.eslintrc.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: '@remix-run/eslint-config',
3+
};

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.cache
2+
.env
3+
.next
4+
.vscode
5+
*.DS_Store
6+
*.log
7+
build
8+
coverage
9+
dist
10+
logs
11+
node_modules
12+
npm-debug.log

.prettierignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.next
2+
build
3+
docs
4+
public

Dockerfile

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# DEV BUILD STEP
2+
FROM node:16.14-alpine3.14 as devBuild
3+
WORKDIR /app
4+
5+
# Log the npm config and env variables
6+
ENV NODE_ENV=production
7+
RUN npm config ls
8+
RUN env
9+
10+
# Install dependencies first so docker caches them
11+
COPY package.json package-lock.json /app/
12+
RUN ls -a
13+
RUN npm install --production=false
14+
15+
# Copy the source code and build
16+
COPY /app/public ./public
17+
COPY /app/src ./src
18+
COPY /app/remix.config.js ./remix.config.js
19+
COPY /app/remix.env.d.ts ./remix.env.d.ts
20+
COPY /app/tsconfig.json ./tsconfig.json
21+
22+
RUN npm run build:prod
23+
RUN ls -a
24+
25+
# PROD BUILD STEP
26+
FROM node:16.14-alpine3.14
27+
28+
# Create an app directory on the container
29+
WORKDIR /app
30+
ENV NODE_ENV=production
31+
32+
# Project copy build, install only prod dependencies
33+
COPY --from=devBuild /app/build ./build
34+
COPY --from=devBuild /app/public ./public
35+
COPY --from=devBuild /app/remix.config.js ./remix.config.js
36+
COPY package.json package-lock.json healthcheck.js ./
37+
38+
RUN ls -a
39+
40+
RUN npm install @remix-run/serve@1.1.3
41+
42+
# Expose the container port to the OS
43+
# docker run takes -p argument to forward this port to network
44+
EXPOSE 3000
45+
46+
# Start the application
47+
CMD npm run start:prod
48+
49+
HEALTHCHECK --interval=30s --timeout=12s --start-period=30s \
50+
CMD node /healthcheck.js

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2017, Clinton D'Annolfo
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
13+
all 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
21+
THE SOFTWARE.

README.md

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<h2 align="center">Hacker News Clone Remix/React</h2>
2+
3+
<p align="center">
4+
<a href="https://github.com/clintonwoo/hackernews-remix-react/stargazers"><img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/clintonwoo/hackernews-remix-react?style=social"></a>
5+
<a href="https://github.com/clintonwoo/"><img alt="GitHub Followers" src="https://img.shields.io/github/followers/clintonwoo.svg?style=social&label=Follow"></a>
6+
<a href="https://github.com/clintonwoo/hackernews-remix-react/issues"><img alt="GitHub Issues" src="https://img.shields.io/github/issues/clintonwoo/hackernews-remix-react.svg"></a>
7+
<a href="https://github.com/clintonwoo/hackernews-remix-react/pulls"><img alt="GitHub Pull Requests" src="https://img.shields.io/github/issues-pr-raw/clintonwoo/hackernews-remix-react.svg"></a>
8+
</p>
9+
10+
This is a clone of Hacker News written in TypeScript using Remix and React.
11+
12+
It is intended to be an example or boilerplate to help you structure your projects using production-ready technologies.
13+
14+
The project implements the publically available parts of the Hacker News site API, with some remaining functionality implemented in-memory.
15+
16+
<p align="center" margin-bottom="0">
17+
<a href="https://remix.hnclone.win" target="_blank">
18+
<img alt="Hacker News Clone Demo" width="600" height="auto" src="docs/hn-screenshot-seal.webp">
19+
</a>
20+
</p>
21+
<p align="center">
22+
<a href="https://remix.hnclone.win">Live Demo</a>
23+
</p>
24+
25+
## Overview
26+
27+
### Featuring
28+
29+
- Remix (Server side rendering framework)
30+
- React (Declarative UI)
31+
- ESBuild (via Remix, sub-second production builds)
32+
- TypeScript (Static typing)
33+
- Authentication via Cookies (plain JS)
34+
- Jest (Test runner)
35+
- Prettier (Code formatter)
36+
37+
### Benefits
38+
39+
**UI**
40+
41+
- Website works with JavaScript disabled (`Remix`)
42+
- Declarative UI (`React`)
43+
- Minimalistic client-side UI rendering (`Remix`)
44+
- Pre-fetch page assets (`Remix`)
45+
- JS Code splitting (`Remix`)
46+
- Loading state spinners not required (`Remix`)
47+
48+
**Server**
49+
50+
- Server Side rendering (`Remix`)
51+
- Universal TypeScript/JavaScript (`Web standards`)
52+
- Deployable on FaaS (Functions as a Service), edge workers or on your own NodeJS server (`Remix`)
53+
- Asset bundler (`ESBuild` via `Remix`)
54+
55+
**Dev/Test**
56+
57+
- Hot module reloading (`remix`)
58+
- Snapshot testing (`Jest`)
59+
- JS/TS best practices (`eslint`)
60+
61+
## How it works
62+
63+
Remix emphasises web primitives and fundamentals. So requests are made generally using Remix's `<Link>`s and `<Form>`s which add some extra functionality on top of the regular `<a>` and `<form>` tags.
64+
65+
Remix `routes` folder correlates to route-matching UI views with layouts and endpoints for GET (loader) or all other HTTP verb methods (action). You can have endpoints with no UI and UI with no endpoints, or mixed.
66+
67+
Remix takes care of the build system (using ESBuild), which works incredibly quickly and is a pleasure to work with. Remix implements code-splitting, HTTP headers, asset bundling and various optimizations to make the site run fast in real-world scenarios.
68+
69+
Remix can run in a number of runtime environments so the architecture for your app could be widely different depending on your requirements. You could deploy it on an edge network (like Cloudflare Workers) or run it with NodeJS inside a cloud VM or VPS, for example.
70+
71+
### How to build and start
72+
73+
Start with `npm install`.
74+
75+
You can build and start with file watching using `npm run dev`.
76+
77+
Or you can do a regular build and start using `npm run build` and `npm run start`.
78+
79+
### One Command Setup & Run
80+
81+
You can download and run the repo with one command to rule them all:
82+
83+
`git clone https://github.com/clintonwoo/hackernews-react-remix.git && cd hackernews-react-remix && npm install && npm run dev`
84+
85+
## Contributing
86+
87+
File an issue for ideas, conversation or feedback. Pull requests are welcome.
88+
89+
## Community
90+
91+
After you ★Star this project, follow [@ClintonDAnnolfo](https://twitter.com/clintondannolfo) on Twitter.

docs/hn-screenshot-seal.webp

189 KB
Binary file not shown.

healthcheck.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// This file is used to run health checks with Node in the Docker container
2+
3+
var http = require('http');
4+
5+
var options = {
6+
host: 'localhost',
7+
port: '3000',
8+
timeout: 2000,
9+
};
10+
11+
var request = http.request(options, (res) => {
12+
console.log(`STATUS: ${res.statusCode}`);
13+
14+
if (res.statusCode == 200) {
15+
process.exit(0);
16+
} else {
17+
process.exit(1);
18+
}
19+
});
20+
21+
request.on('error', function (err) {
22+
console.log('ERROR');
23+
process.exit(1);
24+
});
25+
26+
request.end();

jest-setup.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const { installGlobals } = require('@remix-run/node');
2+
3+
// This installs globals such as "fetch", "Response", "Request" and "Headers".
4+
installGlobals();
5+
6+
// Fail tests on any warning
7+
// console.error = (message) => {
8+
// throw new Error(message);
9+
// };

jest.config.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2+
module.exports = {
3+
moduleNameMapper: {
4+
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
5+
'<rootDir>/src/__mocks__/file-mock.js',
6+
'\\.(css|less)$': '<rootDir>/src/__mocks__/style-mock.js',
7+
},
8+
preset: 'ts-jest',
9+
setupFilesAfterEnv: ['<rootDir>/jest-setup.js'],
10+
testEnvironment: 'node',
11+
globals: {
12+
'ts-jest': {
13+
diagnostics: false,
14+
},
15+
},
16+
};

0 commit comments

Comments
 (0)