Skip to content

Commit 152cf0f

Browse files
committed
#514 task 1
1 parent 2bb5868 commit 152cf0f

File tree

11 files changed

+2940
-3428
lines changed

11 files changed

+2940
-3428
lines changed

builderbook/components/Header.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Hidden from '@mui/material/Hidden';
66
import Button from '@mui/material/Button';
77
import Avatar from '@mui/material/Avatar';
88

9+
910
import MenuWithAvatar from './MenuWithAvatar';
1011

1112
const optionsMenuCustomer = [
@@ -115,8 +116,9 @@ function Header({ user, hideHeader, redirectUrl }) {
115116
pathname: '/login',
116117
query: { redirectUrl },
117118
}}
119+
style={{ margin: '0px 20px 0px auto' }}
118120
>
119-
<a style={{ margin: '0px 20px 0px auto' }}>Log in</a>
121+
Log in
120122
</Link>
121123
)}
122124
</Grid>

builderbook/lib/withAuth.jsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,7 @@ export default function withAuth(
6767
return null;
6868
}
6969

70-
return (
71-
<>
72-
<BaseComponent {...this.props} />
73-
</>
74-
);
70+
return <BaseComponent {...this.props} />;
7571
}
7672
}
7773

builderbook/next.config.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1-
module.exports = {
1+
const withTM = require('next-transpile-modules')([ // eslint-disable-line
2+
'@mui/material',
3+
'@mui/icons-material',
4+
]);
5+
6+
module.exports = withTM({
7+
typescript: {
8+
ignoreBuildErrors: true,
9+
},
210
poweredByHeader: false,
3-
webpack5: true,
4-
};
11+
swcMinify: true,
12+
experimental: {
13+
forceSwcTransforms: true,
14+
},
15+
modularizeImports: {
16+
'@mui/material/?(((\\w*)?/?)*)': {
17+
transform: '@mui/material/{{ matches.[1] }}/{{member}}',
18+
},
19+
'@mui/icons-material/?(((\\w*)?/?)*)': {
20+
transform: '@mui/icons-material/{{ matches.[1] }}/{{member}}',
21+
},
22+
},
23+
});

builderbook/package.json

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"version": "0.0.1",
44
"license": "MIT",
55
"engines": {
6-
"node": "14.18.1",
7-
"yarn": "1.22.5"
6+
"node": "16.15.1",
7+
"yarn": "1.22.19"
88
},
99
"scripts": {
1010
"dev": "nodemon server/server.js --watch server",
@@ -17,55 +17,57 @@
1717
"coverageDirectory": "./.coverage"
1818
},
1919
"dependencies": {
20-
"@emotion/cache": "^11.7.1",
21-
"@emotion/react": "^11.9.0",
22-
"@emotion/server": "^11.4.0",
23-
"@emotion/styled": "^11.8.1",
24-
"@mui/icons-material": "^5.8.3",
25-
"@mui/material": "^5.8.3",
26-
"@octokit/oauth-authorization-url": "^4.1.0",
27-
"@octokit/rest": "^18.0.3",
28-
"@stripe/stripe-js": "^1.21.1",
29-
"aws-sdk": "^2.796.0",
20+
"@emotion/cache": "^11.10.5",
21+
"@emotion/react": "^11.10.5",
22+
"@emotion/server": "^11.10.0",
23+
"@emotion/styled": "^11.10.5",
24+
"@mui/icons-material": "^5.11.0",
25+
"@mui/material": "^5.11.4",
26+
"@octokit/oauth-authorization-url": "^5.0.0",
27+
"@octokit/rest": "^19.0.5",
28+
"@stripe/stripe-js": "^1.46.0",
29+
"aws-sdk": "^2.1291.0",
3030
"compression": "^1.7.4",
31-
"connect-mongo": "^3.2.0",
32-
"dotenv": "^8.2.0",
33-
"express": "^4.17.1",
31+
"connect-mongo": "^4.6.0",
32+
"dotenv": "^16.0.3",
33+
"express": "^4.18.2",
3434
"express-session": "^1.17.1",
3535
"front-matter": "^4.0.2",
3636
"he": "^1.2.0",
37-
"helmet": "^4.1.0-rc.2",
38-
"highlight.js": "^10.1.2",
39-
"isomorphic-unfetch": "^3.0.0",
37+
"helmet": "^6.0.1",
38+
"highlight.js": "^11.7.0",
39+
"isomorphic-unfetch": "^4.0.2",
4040
"lodash": "^4.17.21",
41-
"marked": "^1.2.7",
42-
"mongoose": "^5.10.0",
43-
"next": "^12.1.6",
41+
"marked": "^4.2.5",
42+
"mongodb": "^4.1.0",
43+
"mongoose": "^6.8.3",
44+
"next": "^13.1.1",
4445
"node-fetch": "^2.6.1",
4546
"nprogress": "^0.2.0",
4647
"passport": "^0.6.0",
4748
"passport-google-oauth": "^2.0.0",
4849
"prop-types": "^15.7.2",
49-
"qs": "^6.10.1",
50-
"react": "^17.0.2",
51-
"react-dom": "^17.0.2",
52-
"sitemap": "^6.2.0",
53-
"stripe": "^8.129.0",
54-
"winston": "^3.3.3"
50+
"qs": "^6.11.0",
51+
"react": "^18.2.0",
52+
"react-dom": "^18.2.0",
53+
"sitemap": "^7.1.1",
54+
"stripe": "^11.6.0",
55+
"winston": "^3.8.2"
5556
},
5657
"devDependencies": {
57-
"@babel/core": "^7.16.0",
58+
"@babel/core": "^7.20.12",
5859
"babel-eslint": "^10.1.0",
59-
"eslint": "^7.25.0",
60-
"eslint-config-airbnb": "^18.2.1",
61-
"eslint-config-prettier": "^6.15.0",
60+
"eslint": "^7.32.0",
61+
"eslint-config-airbnb": "^19.0.4",
62+
"eslint-config-prettier": "^8.6.0",
6263
"eslint-plugin-import": "^2.22.1",
63-
"eslint-plugin-jsx-a11y": "^6.4.1",
64-
"eslint-plugin-prettier": "^3.1.4",
65-
"eslint-plugin-react": "^7.21.5",
66-
"eslint-plugin-react-hooks": "^4.2.0",
67-
"jest": "^26.6.3",
68-
"nodemon": "^2.0.15",
69-
"prettier": "^2.2.1"
64+
"eslint-plugin-jsx-a11y": "^6.7.0",
65+
"eslint-plugin-prettier": "^4.2.1",
66+
"eslint-plugin-react": "^7.31.11",
67+
"eslint-plugin-react-hooks": "^4.6.0",
68+
"jest": "^29.3.1",
69+
"next-transpile-modules": "^10.0.0",
70+
"nodemon": "^2.0.20",
71+
"prettier": "^2.8.2"
7072
}
7173
}

builderbook/pages/_document.jsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ MyDocument.getInitialProps = async (ctx) => {
8686

8787
// You can consider sharing the same emotion cache between all the SSR requests to speed up performance.
8888
// However, be aware that it can have global side effects.
89-
const cache = createCache({
90-
key: 'css',
91-
prepend: true,
92-
});
89+
const cache = createCache({ key: 'css' });
9390
const { extractCriticalToChunks } = createEmotionServer(cache);
9491

9592
ctx.renderPage = () =>

builderbook/pages/admin/book-detail.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function BookDetail({ slug }) {
8383
as={`/books/${book.slug}/${ch.slug}`}
8484
href={`/public/read-chapter?bookSlug=${book.slug}&chapterSlug=${ch.slug}`}
8585
>
86-
<a>{ch.title}</a>
86+
{ch.title}
8787
</Link>
8888
</li>
8989
))}

builderbook/pages/admin/index.jsx

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,36 @@ const propTypes = {
1919
).isRequired,
2020
};
2121

22-
const Index = ({ books }) => (
23-
<div style={{ padding: '10px 45px' }}>
24-
<div>
25-
<h2>Books</h2>
26-
<Link href="/admin/add-book">
27-
<Button variant="contained" color="primary">
28-
Add book
29-
</Button>
30-
</Link>
31-
<p />
32-
<ul>
33-
{books &&
34-
books.length > 0 &&
35-
books.map((b) => (
36-
<li key={b._id}>
37-
<Link as={`/admin/book-detail/${b.slug}`} href={`/admin/book-detail?slug=${b.slug}`}>
38-
<a>{b.name}</a>
39-
</Link>
40-
</li>
41-
))}
42-
</ul>
43-
<br />
22+
function Index({ books }) {
23+
return (
24+
<div style={{ padding: '10px 45px' }}>
25+
<div>
26+
<h2>Books</h2>
27+
<Link href="/admin/add-book">
28+
<Button variant="contained" color="primary">
29+
Add book
30+
</Button>
31+
</Link>
32+
<p />
33+
<ul>
34+
{books &&
35+
books.length > 0 &&
36+
books.map((b) => (
37+
<li key={b._id}>
38+
<Link
39+
as={`/admin/book-detail/${b.slug}`}
40+
href={`/admin/book-detail?slug=${b.slug}`}
41+
>
42+
{b.name}
43+
</Link>
44+
</li>
45+
))}
46+
</ul>
47+
<br />
48+
</div>
4449
</div>
45-
</div>
46-
);
50+
);
51+
}
4752

4853
Index.propTypes = propTypes;
4954

builderbook/pages/customer/my-books.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function MyBooks({ purchasedBooks }) {
3737
as={`/books/${book.slug}/introduction`}
3838
href={`/public/read-chapter?bookSlug=${book.slug}&chapterSlug=introduction`}
3939
>
40-
<a>{book.name}</a>
40+
{book.name}
4141
</Link>
4242
</li>
4343
))}

builderbook/pages/public/read-chapter.jsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,10 @@ function ReadChapterFunctional({
240240
<Link
241241
as={`/books/${book.slug}/${ch.slug}`}
242242
href={`/public/read-chapter?bookSlug=${book.slug}&chapterSlug=${ch.slug}`}
243+
style={{ color: chapterInsideState._id === ch._id ? '#1565C0' : '#222' }}
244+
onClick={closeTocWhenMobile}
243245
>
244-
<a // eslint-disable-line
245-
style={{ color: chapterInsideState._id === ch._id ? '#1565C0' : '#222' }}
246-
onClick={closeTocWhenMobile}
247-
>
248-
{ch.title}
249-
</a>
246+
{ch.title}
250247
</Link>
251248
{chapterInsideState._id === ch._id ? renderSections() : null}
252249
</li>

builderbook/server/server.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const express = require('express');
22
const session = require('express-session');
33
const mongoSessionStore = require('connect-mongo');
4+
45
const next = require('next');
56
const mongoose = require('mongoose');
67
const compression = require('compression');
@@ -22,13 +23,18 @@ require('dotenv').config();
2223
const dev = process.env.NODE_ENV !== 'production';
2324
const MONGO_URL = dev ? process.env.MONGO_URL_TEST : process.env.MONGO_URL;
2425

25-
const options = {
26-
useNewUrlParser: true,
27-
useCreateIndex: true,
28-
useFindAndModify: false,
29-
useUnifiedTopology: true,
30-
};
31-
mongoose.connect(MONGO_URL, options);
26+
(async () => {
27+
try {
28+
mongoose.set('strictQuery', false);
29+
await mongoose.connect(MONGO_URL);
30+
logger.info('connected to db');
31+
32+
// async tasks, for ex, inserting email templates to db
33+
// logger.info('finished async tasks');
34+
} catch (err) {
35+
logger.error(`error: ${err}`);
36+
}
37+
})();
3238

3339
const port = process.env.PORT || 8000;
3440
const ROOT_URL = getRootUrl();
@@ -44,7 +50,7 @@ const handle = app.getRequestHandler();
4450
app.prepare().then(async () => {
4551
const server = express();
4652

47-
server.use(helmet({ contentSecurityPolicy: false }));
53+
server.use(helmet({ contentSecurityPolicy: false, crossOriginEmbedderPolicy: false }));
4854
server.use(compression());
4955

5056
server.use(express.json());
@@ -54,13 +60,12 @@ app.prepare().then(async () => {
5460
handle(req, res);
5561
});
5662

57-
const MongoStore = mongoSessionStore(session);
58-
const sess = {
63+
const sessionOptions = {
5964
name: process.env.SESSION_NAME,
6065
secret: process.env.SESSION_SECRET,
61-
store: new MongoStore({
62-
mongooseConnection: mongoose.connection,
63-
ttl: 14 * 24 * 60 * 60, // expires in 14 days
66+
store: mongoSessionStore.create({
67+
mongoUrl: MONGO_URL,
68+
ttl: 14 * 24 * 60 * 60, // save session 14 days
6469
}),
6570
resave: false,
6671
saveUninitialized: false,
@@ -73,10 +78,11 @@ app.prepare().then(async () => {
7378

7479
if (!dev) {
7580
server.set('trust proxy', 1); // sets req.hostname, req.ip
76-
sess.cookie.secure = true; // sets cookie over HTTPS only
81+
sessionOptions.cookie.secure = true; // sets cookie over HTTPS only
7782
}
7883

79-
server.use(session(sess));
84+
const sessionMiddleware = session(sessionOptions);
85+
server.use(sessionMiddleware);
8086

8187
// await insertTemplates();
8288

0 commit comments

Comments
 (0)