Skip to content

Commit

Permalink
book update in 10-end and 10-end-functional #193
Browse files Browse the repository at this point in the history
  • Loading branch information
klyburke committed Jan 21, 2023
1 parent 5a323f9 commit 0983256
Show file tree
Hide file tree
Showing 40 changed files with 15,147 additions and 17,967 deletions.
30 changes: 15 additions & 15 deletions book/10-begin/app/pages/invitation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { observer } from 'mobx-react';
import Error from 'next/error';
import Head from 'next/head';
import Router from 'next/router';
import { NextPageContext } from 'next';
import React from 'react';

import LoginButton from '../components/common/LoginButton';
Expand All @@ -12,25 +13,24 @@ import { Team } from '../lib/store/team';
import { Store } from '../lib/store';
import withAuth from '../lib/withAuth';

type Props = { store: Store; team: Team; token: string };
export async function getServerSideProps(context: NextPageContext) {
const { token } = context.query;

class InvitationPageComp extends React.Component<Props> {
public static async getInitialProps(ctx) {
const { token } = ctx.query;
if (!token) {
return {};
}

try {
const { team } = await getTeamByTokenApiMethod(token, ctx.req);
try {
const { team } = await getTeamByTokenApiMethod(token as string, context.req);

return { team, token };
} catch (error) {
console.log(error);
return {};
if (team && token) {
return { props: { team, token } };
} else {
return { props: {} };
}
} catch (error) {
console.log(error);
return { props: {} };
}
}

class InvitationPageComp extends React.Component<{ store: Store; team: Team; token: string }> {
public render() {
const { team, token, store } = this.props;

Expand Down Expand Up @@ -73,7 +73,7 @@ class InvitationPageComp extends React.Component<Props> {
);
}

public async componentDidMount() {
public componentDidMount() {
const { store, team, token } = this.props;

const user = store.currentUser;
Expand Down
2 changes: 1 addition & 1 deletion book/10-end-functional/api/nodemon.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"watch": ["server"],
"exec": "ts-node --project tsconfig.server.json",
"exec": "ts-node --project tsconfig.json",
"ext": "ts"
}
74 changes: 37 additions & 37 deletions book/10-end-functional/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"version": "1.0.0",
"license": "MIT",
"engines": {
"node": "14.18.1",
"yarn": "1.22.5"
"node": "16.15.1",
"yarn": "1.22.19"
},
"scripts": {
"dev": "nodemon server/server.ts",
"lint": "eslint . --ext .ts,.tsx",
"test": "jest",
"postinstall": "rm -rf production-server/",
"build": "tsc --project tsconfig.server.json",
"build": "tsc --project tsconfig.json",
"start": "node production-server/server.js"
},
"jest": {
Expand All @@ -22,52 +22,52 @@
"testEnvironment": "node"
},
"dependencies": {
"aws-sdk": "^2.796.0",
"bcrypt": "^5.0.0",
"aws-sdk": "^2.1286.0",
"bcrypt": "^5.1.0",
"compression": "^1.7.4",
"connect-mongo": "^3.2.0",
"connect-mongo": "^4.6.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-session": "^1.17.1",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"express-session": "^1.17.3",
"he": "^1.2.0",
"helmet": "4.1.0-rc.2",
"highlight.js": "^10.5.0",
"lodash": "^4.17.20",
"marked": "^4.0.16",
"mongoose": "^6.3.5",
"helmet": "6.0.1",
"highlight.js": "^11.7.0",
"lodash": "^4.17.21",
"marked": "^4.2.5",
"mongoose": "^6.8.2",
"node-fetch": "^2.6.1",
"passport": "^0.6.0",
"passport-google-oauth": "^2.0.0",
"passwordless": "^1.1.3",
"passwordless-tokenstore": "^0.0.10",
"socket.io": "^4.2.0",
"stripe": "^8.129.0",
"typescript": "^4.7.3",
"winston": "^3.3.3"
"socket.io": "^4.5.4",
"stripe": "^11.5.0",
"typescript": "^4.9.4",
"winston": "^3.8.2"
},
"devDependencies": {
"@types/connect-mongo": "^3.1.3",
"@types/dotenv": "^8.2.0",
"@types/express": "^4.11.1",
"@types/express-session": "^1.15.8",
"@types/jest": "^22.2.3",
"@types/lodash": "^4.14.108",
"@types/marked": "^4.0.3",
"@types/mongoose": "^5.5.43",
"@types/node": "^12.12.2",
"@types/node-fetch": "^1.6.9",
"@types/passport": "^1.0.8",
"@types/express": "^4.17.15",
"@types/express-session": "^1.17.5",
"@types/jest": "^29.2.5",
"@types/lodash": "^4.14.191",
"@types/marked": "^4.0.8",
"@types/mongoose": "^5.11.97",
"@types/node": "^18.11.18",
"@types/node-fetch": "^2.6.2",
"@types/passport": "^1.0.11",
"@types/socket.io": "^3.0.2",
"@typescript-eslint/eslint-plugin": "^4.2.0",
"@typescript-eslint/parser": "^4.2.0",
"eslint": "^7.25.0",
"eslint-config-prettier": "^7.1.0",
"eslint-plugin-prettier": "^3.3.1",
"jest": "^26.4.2",
"nodemon": "^2.0.7",
"prettier": "^2.2.1",
"ts-jest": "^26.4.4",
"ts-node": "^10.8.1"
"@typescript-eslint/eslint-plugin": "^5.47.1",
"@typescript-eslint/parser": "^5.47.1",
"eslint": "^8.31.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.3.1",
"nodemon": "^2.0.20",
"prettier": "^2.8.1",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1"
}
}
2 changes: 1 addition & 1 deletion book/10-end-functional/api/server/models/Post.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as mongoose from 'mongoose';

import * as he from 'he';
import * as hljs from 'highlight.js';
import hljs from 'highlight.js';
import { marked } from 'marked';

import Discussion from './Discussion';
Expand Down
19 changes: 8 additions & 11 deletions book/10-end-functional/api/server/server.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as mongoSessionStore from 'connect-mongo';
import * as cors from 'cors';
import * as express from 'express';
import * as session from 'express-session';
import * as httpModule from 'http';
import * as mongoose from 'mongoose';

import mongoSessionStore = require('connect-mongo');

import api from './api';
import { setupGoogle } from './google-auth';
import { setupPasswordless } from './passwordless-auth';
Expand All @@ -14,20 +15,20 @@ import { stripeWebhookAndCheckoutCallback } from './stripe';
import logger from './logger';

import * as compression from 'compression';
import * as helmet from 'helmet';
import helmet from 'helmet';

// eslint-disable-next-line
require('dotenv').config();

const dev = process.env.NODE_ENV !== 'production';
const port = process.env.PORT || 8000;

mongoose.connect(dev ? process.env.MONGO_URL_TEST : process.env.MONGO_URL);
const MONGO_URL = dev ? process.env.MONGO_URL_TEST : process.env.MONGO_URL;

// check connection
(async () => {
try {
await mongoose.connect(dev ? process.env.MONGO_URL_TEST : process.env.MONGO_URL);
mongoose.set('strictQuery', false);
await mongoose.connect(MONGO_URL);
logger.info('connected to db');

// async tasks, for ex, inserting email templates to db
Expand All @@ -54,16 +55,12 @@ stripeWebhookAndCheckoutCallback({ server });

server.use(express.json());

const MongoStore = mongoSessionStore(session);

const sessionOptions = {
name: process.env.SESSION_NAME,
secret: process.env.SESSION_SECRET,
store: new MongoStore({
mongooseConnection: mongoose.connection,
store: mongoSessionStore.create({
mongoUrl: MONGO_URL,
ttl: 14 * 24 * 60 * 60, // save session 14 days
autoRemove: 'interval',
autoRemoveInterval: 1440, // clears every day
}),
resave: false,
saveUninitialized: false,
Expand Down
2 changes: 1 addition & 1 deletion book/10-end-functional/api/server/stripe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const dev = process.env.NODE_ENV !== 'production';

const stripeInstance = new Stripe(
dev ? process.env.STRIPE_TEST_SECRETKEY : process.env.STRIPE_LIVE_SECRETKEY,
{ apiVersion: '2020-08-27' },
{ apiVersion: '2022-11-15' },
);

function createSession({
Expand Down
8 changes: 6 additions & 2 deletions book/10-end-functional/api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
"baseUrl": ".",
"experimentalDecorators": true,
"typeRoots": ["./node_modules/@types"],
"lib": ["es2015", "es2016"]
"target": "es2020",
"lib": ["es2020"],
"module": "commonjs",
"outDir": "production-server/",
"downlevelIteration": true,
},
"exclude": ["production-server", "node_modules"]
"include": ["./server/**/*.ts"]
}
9 changes: 0 additions & 9 deletions book/10-end-functional/api/tsconfig.server.json

This file was deleted.

Loading

0 comments on commit 0983256

Please sign in to comment.