Skip to content

Commit ef9a42b

Browse files
committed
factor out prod scripts
1 parent e1e044e commit ef9a42b

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

components/article/ArticleList.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ const ArticleList = props => {
5252
const setFavorited = []
5353
const favoritesCount = []
5454
const setFavoritesCount = []
55+
// MUST be DEFAULT_LIMIT and not articles.length, because articles.length
56+
// can happen a variable number of times on index page due to:
57+
// * load ISR page logged off on global
58+
// * login, which leads to feed instead of global
59+
// and calling hooks like useState different number of times is a capital sin
60+
// in React and makes everything blow up.
5561
for (let i = 0; i < DEFAULT_LIMIT; i++) {
5662
[favorited[i], setFavorited[i]] = React.useState(false);
5763
[favoritesCount[i], setFavoritesCount[i]] = React.useState(0);

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
"back-test": "NODE_ENV=test npm run dev",
88
"build": "./bin/sync-db.js && next build",
99
"build-dev": "./bin/sync-db.js && NEXT_PUBLIC_NODE_ENV=development npm run build",
10-
"build-prod": "NODE_ENV=production DATABASE_URL='postgres://node_express_sequelize_realworld_user:a@localhost:5432/node_express_sequelize_realworld' ./bin/sync-db.js && NODE_ENV=production DATABASE_URL='postgres://node_express_sequelize_realworld_user:a@localhost:5432/node_express_sequelize_realworld' npm run build",
10+
"build-prod": "./prod.sh ./bin/sync-db.js && ./prod.sh npm run build",
1111
"deploy": " git push -f heroku-next next:master && git push",
1212
"dev": "NODE_OPTIONS='--unhandled-rejections=strict' nodemon ./app.js",
1313
"dev-demo": "NEXT_PUBLIC_DEMO=true npm run dev",
14-
"seed-prod": "NODE_ENV=production DATABASE_URL='postgres://node_express_sequelize_realworld_user:a@localhost:5432/node_express_sequelize_realworld' ./bin/generate-demo-data.js --force-production",
14+
"seed-prod": "./prod.sh ./bin/generate-demo-data.js --force-production",
1515
"start": "node --unhandled-rejections=strict ./app.js",
1616
"start-dev": "NEXT_PUBLIC_NODE_ENV=development NODE_ENV_NEXT_SERVER_ONLY=production node --unhandled-rejections=strict ./app.js",
17-
"start-prod": "env $(cat .env | xargs) NODE_ENV=production DATABASE_URL='postgres://node_express_sequelize_realworld_user:a@localhost:5432/node_express_sequelize_realworld' npm start",
17+
"start-prod": "./prod.sh npm start",
1818
"test": "mocha test --ignore-leaks test.js",
1919
"test-api": "./realworld/api/run-api-tests.sh"
2020
},

prod.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
set -eux
3+
env $(cat .env | xargs) NODE_ENV=production "$@"

0 commit comments

Comments
 (0)