Skip to content

Commit c95b84e

Browse files
committed
create 10-end-functional folder
1 parent caf5e0a commit c95b84e

File tree

115 files changed

+26649
-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.

115 files changed

+26649
-0
lines changed

Diff for: book/10-end-functional/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.env
2+
node_modules
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
branch-defaults:
2+
default:
3+
environment: api-saas-boilerplate-env
4+
environment-defaults:
5+
api-saas-boilerplate-env:
6+
branch: null
7+
repository: null
8+
global:
9+
application_name: api-saas-boilerplate-app
10+
default_ec2_keyname: null
11+
default_platform: Node.js 14 running on 64bit Amazon Linux 2
12+
default_region: us-east-1
13+
include_git_submodules: true
14+
instance_profile: null
15+
platform_name: null
16+
platform_version: null
17+
profile: null
18+
sc: null
19+
workspace_type: Application

Diff for: book/10-end-functional/api/.env.example

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Used in api/server/server.ts
2+
MONGO_URL_TEST=
3+
MONGO_URL=
4+
SESSION_NAME=
5+
SESSION_SECRET=
6+
COOKIE_DOMAIN=
7+
8+
# Used in api/server/google.ts
9+
GOOGLE_CLIENTID=
10+
GOOGLE_CLIENTSECRET=
11+
12+
# Used in api/server/aws-s3.ts and api/server/aws-ses.ts
13+
AWS_REGION=
14+
AWS_ACCESSKEYID=
15+
AWS_SECRETACCESSKEY=
16+
17+
# Used in api/server/models/Invitation.ts and api/server/models/User.ts
18+
EMAIL_SUPPORT_FROM_ADDRESS=
19+
20+
# Used in api/server/mailchimp.ts
21+
MAILCHIMP_API_KEY=
22+
MAILCHIMP_REGION=
23+
MAILCHIMP_SAAS_ALL_LIST_ID=
24+
25+
# All env variables above this line are needed for successful user signup
26+
27+
# Used in api/server/stripe.ts
28+
STRIPE_TEST_SECRETKEY=sk_test_xxxxxx
29+
STRIPE_LIVE_SECRETKEY=sk_live_xxxxxx
30+
31+
STRIPE_TEST_PLANID=plan_xxxxxx
32+
STRIPE_LIVE_PLANID=plan_xxxxxx
33+
34+
STRIPE_LIVE_ENDPOINTSECRET=whsec_xxxxxx
35+
36+
# Optionally determine the URL
37+
URL_APP="http://localhost:3000"
38+
URL_API="http://localhost:8000"
39+
PRODUCTION_URL_APP="https://saas-app.async-await.com"
40+
PRODUCTION_URL_API="https://saas-api.async-await.com"

Diff for: book/10-end-functional/api/.eslintignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.next
2+
production-server
3+
node_modules

Diff for: book/10-end-functional/api/.eslintrc.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = {
2+
parser: "@typescript-eslint/parser",
3+
extends: ["plugin:@typescript-eslint/recommended", "prettier"],
4+
env: {
5+
"es6": true,
6+
"node": true,
7+
},
8+
plugins: ["prettier"],
9+
rules: {
10+
'prettier/prettier': [
11+
'error',
12+
{
13+
singleQuote: true,
14+
trailingComma: 'all',
15+
arrowParens: 'always',
16+
printWidth: 100,
17+
semi: true,
18+
},
19+
],
20+
'@typescript-eslint/no-unused-vars': 'off',
21+
'@typescript-eslint/explicit-function-return-type': 'off',
22+
'@typescript-eslint/no-explicit-any': 'off',
23+
'prefer-arrow-callback': 'error',
24+
'@typescript-eslint/explicit-module-boundary-types': 'off',
25+
},
26+
}

Diff for: book/10-end-functional/api/.gitignore

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
*~
2+
*.swp
3+
tmp/
4+
npm-debug.log
5+
.DS_Store
6+
7+
8+
9+
.build/*
10+
.next
11+
.vscode/
12+
node_modules/
13+
.coverage
14+
.env
15+
now.json
16+
.note
17+
18+
compiled/
19+
production-server/
20+
21+
yarn-error.log

Diff for: book/10-end-functional/api/nodemon.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"watch": ["server"],
3+
"exec": "ts-node --project tsconfig.server.json",
4+
"ext": "ts"
5+
}

Diff for: book/10-end-functional/api/package.json

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"name": "api-same-as-10-end-api",
3+
"version": "1.0.0",
4+
"license": "MIT",
5+
"engines": {
6+
"node": "14.18.1",
7+
"yarn": "1.22.5"
8+
},
9+
"scripts": {
10+
"dev": "nodemon server/server.ts",
11+
"lint": "eslint . --ext .ts,.tsx",
12+
"test": "jest",
13+
"postinstall": "rm -rf production-server/",
14+
"build": "tsc --project tsconfig.server.json",
15+
"start": "node production-server/server.js"
16+
},
17+
"jest": {
18+
"preset": "ts-jest",
19+
"testPathIgnorePatterns": [
20+
"production-server"
21+
],
22+
"testEnvironment": "node"
23+
},
24+
"dependencies": {
25+
"aws-sdk": "^2.796.0",
26+
"bcrypt": "^5.0.0",
27+
"compression": "^1.7.4",
28+
"connect-mongo": "^3.2.0",
29+
"cors": "^2.8.5",
30+
"dotenv": "^8.2.0",
31+
"express": "^4.17.1",
32+
"express-session": "^1.17.1",
33+
"he": "^1.2.0",
34+
"helmet": "4.1.0-rc.2",
35+
"highlight.js": "^10.5.0",
36+
"lodash": "^4.17.20",
37+
"marked": "^4.0.16",
38+
"mongoose": "^6.3.5",
39+
"node-fetch": "^2.6.1",
40+
"passport": "^0.6.0",
41+
"passport-google-oauth": "^2.0.0",
42+
"passwordless": "^1.1.3",
43+
"passwordless-tokenstore": "^0.0.10",
44+
"socket.io": "^4.2.0",
45+
"stripe": "^8.129.0",
46+
"typescript": "^4.7.3",
47+
"winston": "^3.3.3"
48+
},
49+
"devDependencies": {
50+
"@types/connect-mongo": "^3.1.3",
51+
"@types/dotenv": "^8.2.0",
52+
"@types/express": "^4.11.1",
53+
"@types/express-session": "^1.15.8",
54+
"@types/jest": "^22.2.3",
55+
"@types/lodash": "^4.14.108",
56+
"@types/marked": "^4.0.3",
57+
"@types/mongoose": "^5.5.43",
58+
"@types/node": "^12.12.2",
59+
"@types/node-fetch": "^1.6.9",
60+
"@types/passport": "^1.0.8",
61+
"@types/socket.io": "^3.0.2",
62+
"@typescript-eslint/eslint-plugin": "^4.2.0",
63+
"@typescript-eslint/parser": "^4.2.0",
64+
"eslint": "^7.25.0",
65+
"eslint-config-prettier": "^7.1.0",
66+
"eslint-plugin-prettier": "^3.3.1",
67+
"jest": "^26.4.2",
68+
"nodemon": "^2.0.7",
69+
"prettier": "^2.2.1",
70+
"ts-jest": "^26.4.4",
71+
"ts-node": "^10.8.1"
72+
}
73+
}

Diff for: book/10-end-functional/api/server/api/index.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as express from 'express';
2+
3+
import publicExpressRoutes from './public';
4+
import teamMemberExpressRoutes from './team-member';
5+
import teamLeaderApi from './team-leader';
6+
7+
function handleError(err, _, res, __) {
8+
console.error(err.stack);
9+
10+
res.json({ error: err.message || err.toString() });
11+
}
12+
13+
export default function api(server: express.Express) {
14+
server.use('/api/v1/public', publicExpressRoutes, handleError);
15+
server.use('/api/v1/team-member', teamMemberExpressRoutes, handleError);
16+
server.use('/api/v1/team-leader', teamLeaderApi, handleError);
17+
}

Diff for: book/10-end-functional/api/server/api/public.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import * as express from 'express';
2+
3+
import User from '../models/User';
4+
import Invitation from '../models/Invitation';
5+
6+
const router = express.Router();
7+
8+
router.get('/get-user', (req, res) => {
9+
// console.log(req.user);
10+
res.json({ user: req.user || null });
11+
});
12+
13+
router.post('/get-user-by-slug', async (req, res, next) => {
14+
console.log('Express route: /get-user-by-slug');
15+
16+
// req.session.foo = 'bar';
17+
18+
try {
19+
const { slug } = req.body;
20+
21+
const user = await User.getUserBySlug({ slug });
22+
23+
res.json({ user });
24+
} catch (err) {
25+
next(err);
26+
}
27+
});
28+
29+
router.get('/invitations/get-team-by-token', async (req, res, next) => {
30+
const token = req.query.token as string;
31+
32+
try {
33+
const team = await Invitation.getTeamByToken({ token });
34+
35+
res.json({ team });
36+
} catch (err) {
37+
next(err);
38+
}
39+
});
40+
41+
export default router;

0 commit comments

Comments
 (0)