Skip to content

Commit 18bc88a

Browse files
committed
initial commit, setup
0 parents  commit 18bc88a

25 files changed

+891
-0
lines changed

.babelrc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"presets": ["next/babel", "@zeit/next-typescript/babel"],
3+
"plugins": [
4+
[
5+
"module-resolver",
6+
{
7+
"root": ["."],
8+
"alias": {
9+
"client": "./client",
10+
"server": "./server"
11+
}
12+
}
13+
]
14+
]
15+
}

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules/
2+
.next/
3+
package-lock.json
4+
.env
5+
.vscode/
6+
app.yaml
7+
public/report.html

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Help-A-Hacker
2+
3+
This is the repo for the client & server of [help-a-hacker.net](https://help-a-hacker.net). Feel free to contribute; we're always looking for improvements.
4+
5+
The stack used is Nuxt.js and Vue.js on the client, and Express on the server. All in TypeScript.
6+
7+
## Requirements
8+
9+
You must have docker installed on your local machine and know some basic git-fu.
10+
11+
## Setup
12+
13+
Clone the repo onto your local computer:
14+
15+
```
16+
git clone https://github.com/timmyichen/help-a-hacker
17+
```
18+
19+
Install the packages
20+
21+
```
22+
npm install
23+
```
24+
25+
Build and start the server:
26+
27+
```
28+
docker-compose up
29+
```
30+
31+
In a new terminal process, run the following:
32+
33+
```
34+
docker exec -it mongo0 mongo
35+
```
36+
37+
This will be up the mongo shell. Then type in the following to configure the replica set:
38+
39+
```
40+
config={"_id":"rs0","members":[{"_id":0,"host":"mongo0:27017"},{"_id":1,"host":"mongo1:27017"},{"_id":2,"host":"mongo2:27017"}]}
41+
```
42+
43+
```
44+
rs.initiate(config)
45+
```
46+
47+
You should see something that has `"ok" : 1` as the first line.
48+
49+
Restart the server by saving any of the `.ts` files in the `server/` directory.
50+
Later on, you may have to do this when first running `docker-compose` up after a few
51+
seconds as the mongodb replica set may need some time to elect a leader (and the
52+
connection will fail as its trying to do so).

client/Header.tsx

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import * as React from 'react';
2+
import classnames from 'classnames';
3+
import Link from 'next/link';
4+
import { withRouter, WithRouterProps } from 'next/router';
5+
6+
const anonRoutes = {
7+
left: [{ href: '/', label: 'Home' }],
8+
right: [
9+
{ href: '/login', label: 'Log in' },
10+
{ href: '/join', label: 'Join' },
11+
],
12+
};
13+
14+
const authedRoutes = {
15+
left: [{ href: '/event', label: 'Event' }],
16+
right: [
17+
{ href: '/account', label: 'Account' },
18+
{ href: '/logout', label: 'Log out' },
19+
],
20+
};
21+
22+
function Header(props: WithRouterProps) {
23+
const currentPage = props.router ? props.router.pathname : '';
24+
25+
const routes = anonRoutes;
26+
27+
return (
28+
<div className="header">
29+
<div className="route-group">
30+
{routes.left.map(route => (
31+
<Route
32+
key={`route-${route.href}`}
33+
route={route}
34+
isActive={currentPage === route.href}
35+
/>
36+
))}
37+
</div>
38+
<div className="route-group">
39+
{routes.right.map(route => (
40+
<Route
41+
key={`route-${route.href}`}
42+
route={route}
43+
isActive={currentPage === route.href}
44+
/>
45+
))}
46+
</div>
47+
48+
<style jsx>{`
49+
.header {
50+
display: flex;
51+
height: 40px;
52+
border-bottom: 1px solid #ccc;
53+
justify-content: space-between;
54+
}
55+
.route-group {
56+
display: flex;
57+
}
58+
.header :global(.route) {
59+
height: 100%;
60+
font-size: 20px;
61+
display: flex;
62+
align-items: center;
63+
justify-content: center;
64+
padding: 0 20px;
65+
color: black;
66+
cursor: pointer;
67+
text-decoration: none;
68+
}
69+
.header :global(.route:hover) {
70+
background: #ccc;
71+
}
72+
.header :global(.route.active) {
73+
}
74+
`}</style>
75+
</div>
76+
);
77+
}
78+
79+
const Route = ({
80+
route,
81+
isActive,
82+
}: {
83+
route: { href: string; label: string };
84+
isActive: boolean;
85+
}) => (
86+
<Link href={route.href} key={`header-route-${route.label}`}>
87+
<a className={classnames('route', { active: isActive })}>{route.label}</a>
88+
</Link>
89+
);
90+
91+
export default withRouter(Header);

docker-compose.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
version: '3'
2+
services:
3+
app:
4+
image: node:10-alpine
5+
command: 'npm run dev'
6+
volumes:
7+
- .:/usr/ydb2/
8+
working_dir: /usr/ydb2/
9+
ports:
10+
- '8000:8000'
11+
- '8888:8888'
12+
environment:
13+
- MONGO_URI=mongodb://mongo0:27017,mongo1:27017,mongo2:27017/helpahacker?replicaSet=rs0
14+
- SESSION_SECRET=asefiuhaof3aiuhsedf
15+
depends_on:
16+
- mongo0
17+
- mongo1
18+
- mongo2
19+
mongo0:
20+
hostname: mongo0
21+
container_name: localmongo0
22+
image: mongo:4.0-xenial
23+
expose:
24+
- 27017
25+
restart: always
26+
entrypoint: ['/usr/bin/mongod', '--bind_ip_all', '--replSet', 'rs0']
27+
mongo1:
28+
hostname: mongo1
29+
container_name: localmongo1
30+
image: mongo:4.0-xenial
31+
expose:
32+
- 27017
33+
restart: always
34+
entrypoint: ['/usr/bin/mongod', '--bind_ip_all', '--replSet', 'rs0']
35+
mongo2:
36+
hostname: mongo2
37+
container_name: localmongo2
38+
image: mongo:4.0-xenial
39+
expose:
40+
- 27017
41+
restart: always
42+
entrypoint: ['/usr/bin/mongod', '--bind_ip_all', '--replSet', 'rs0']

next.config.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const withTs = require('@zeit/next-typescript');
2+
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
3+
const withCSS = require('@zeit/next-css');
4+
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
5+
6+
// https://github.com/zeit/next-plugins/issues/541
7+
function HACK_removeMinimizeOptionFromCssLoaders(config) {
8+
console.warn(
9+
'HACK: Removing `minimize` option from `css-loader` entries in Webpack config',
10+
);
11+
config.module.rules.forEach(rule => {
12+
if (Array.isArray(rule.use)) {
13+
rule.use.forEach(u => {
14+
if (u.loader === 'css-loader' && u.options) {
15+
delete u.options.minimize;
16+
}
17+
});
18+
}
19+
});
20+
}
21+
22+
module.exports = withCSS(
23+
withTs({
24+
webpack(config, options) {
25+
HACK_removeMinimizeOptionFromCssLoaders(config);
26+
config.resolve.alias.client = './client';
27+
config.resolve.alias.server = './server';
28+
config.module.rules.push({
29+
test: /\.css/i,
30+
use: ['style-loader', 'css-loader'],
31+
});
32+
config.plugins.push(new ForkTsCheckerWebpackPlugin());
33+
// config.plugins.push(new BundleAnalyzerPlugin({ analyzerMode: 'static' }));
34+
return config;
35+
},
36+
}),
37+
);

nodemon.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"ignore": [
3+
"**/*.test.ts",
4+
"**/*.spec.ts",
5+
".git",
6+
"node_modules",
7+
".next"
8+
],
9+
"watch": [
10+
"server",
11+
"types"
12+
],
13+
"exec": "npm run dev",
14+
"ext": "ts"
15+
}

package.json

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
{
2+
"name": "coding-projects",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"tsc": "tsc",
8+
"prod:server": "NODE_ENV=production ts-node --files --transpile-only ./server/index.ts",
9+
"dev:server": "ts-node --files --transpile-only ./server/index.ts",
10+
"start": "npm run prod:server",
11+
"dev": "./node_modules/nodemon/bin/nodemon.js --watch 'server/**/*.ts' --exec 'npm run dev:server'",
12+
"nodemon": "./node_modules/nodemon/bin/nodemon.js",
13+
"next:build": "next build",
14+
"prod:build": "NODE_OPTIONS=--max_old_space_size=1024 next build",
15+
"heroku-postbuild": "npm run prod:build",
16+
"lint:ts": "tslint -c tslint.json '**.ts*'",
17+
"pretty": "prettier --write client/**/*.ts* server/**/*.ts",
18+
"precommit": "lint-staged"
19+
},
20+
"author": "",
21+
"license": "ISC",
22+
"dependencies": {
23+
"@types/connect-mongo": "0.0.43",
24+
"@types/passport": "^1.0.1",
25+
"@types/passport-local": "^1.0.33",
26+
"@types/react-bootstrap": "^0.32.20",
27+
"@zeit/next-typescript": "^1.1.1",
28+
"axios": "^0.19.0",
29+
"babel-plugin-module-resolver": "^3.2.0",
30+
"bcrypt-nodejs": "0.0.3",
31+
"bluebird": "^3.5.5",
32+
"body-parser": "^1.18.3",
33+
"bootstrap": "^4.3.1",
34+
"classnames": "^2.2.6",
35+
"connect-mongo": "^3.0.0",
36+
"dotenv": "^7.0.0",
37+
"express": "^4.16.4",
38+
"express-router-async": "^0.3.0",
39+
"express-session": "^1.16.2",
40+
"fork-ts-checker-webpack-plugin": "^1.3.7",
41+
"hijackresponse": "^4.0.0",
42+
"module-alias": "^2.2.0",
43+
"mongodb": "^3.3.2",
44+
"mongoose": "^5.7.1",
45+
"morgan": "^1.9.1",
46+
"next": "^8.1.0",
47+
"nodemon": "^1.18.11",
48+
"passport": "^0.4.0",
49+
"passport-local": "^1.0.0",
50+
"react": "^16.8.6",
51+
"react-bootstrap": "^1.0.0-beta.12",
52+
"react-dom": "^16.8.6",
53+
"request": "^2.88.0",
54+
"request-promise": "^4.2.4",
55+
"ts-node": "^8.1.0",
56+
"typescript": "^3.4.4",
57+
"validator": "^11.1.0"
58+
},
59+
"devDependencies": {
60+
"@types/axios": "^0.14.0",
61+
"@types/bcrypt-nodejs": "0.0.30",
62+
"@types/bluebird": "^3.5.27",
63+
"@types/body-parser": "^1.17.0",
64+
"@types/classnames": "^2.2.9",
65+
"@types/dotenv": "^6.1.1",
66+
"@types/express": "^4.16.1",
67+
"@types/express-session": "^1.15.14",
68+
"@types/module-alias": "^2.0.0",
69+
"@types/mongodb": "^3.3.3",
70+
"@types/mongoose": "^5.5.18",
71+
"@types/morgan": "^1.7.35",
72+
"@types/next": "^8.0.3",
73+
"@types/node": "^12.0.10",
74+
"@types/react": "^16.8.23",
75+
"@types/request": "^2.48.2",
76+
"@types/request-promise": "^4.1.44",
77+
"@types/styled-jsx": "^2.2.8",
78+
"@types/validator": "^10.11.3",
79+
"husky": "^1.3.1",
80+
"lint-staged": "^8.1.5",
81+
"node-typescript": "^0.1.3",
82+
"prettier": "^1.17.0",
83+
"tslint": "^5.16.0",
84+
"tslint-config-prettier": "^1.18.0",
85+
"webpack-bundle-analyzer": "^3.3.2"
86+
},
87+
"lint-staged": {
88+
"*.{ts,tsx}": [
89+
"npm run pretty",
90+
"git add"
91+
]
92+
},
93+
"prettier": {
94+
"trailingComma": "all",
95+
"singleQuote": true
96+
},
97+
"_moduleAliases": {
98+
"server": "server",
99+
"client": "client"
100+
}
101+
}

0 commit comments

Comments
 (0)