Skip to content

Commit c397fd4

Browse files
committed
Update webpack config so that preview server works in prod
1 parent cf8f0ed commit c397fd4

File tree

12 files changed

+82
-95
lines changed

12 files changed

+82
-95
lines changed

docker-compose-development.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ services:
1616
- /usr/src/app/node_modules
1717
ports:
1818
- '8000:8000'
19+
- '8002:8002'
1920
depends_on:
2021
- mongo
2122
volumes:

docker-compose.yml

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,42 @@ services:
1313
# image: index.docker.io/catarak/p5.js-web-editor:latest
1414
# uncomment the following lines if you don't want export all of the variables
1515
# defined in your .env file for testing
16-
# env_file:
16+
env_file:
1717
# - "$PWD/.env.production"
18-
environment:
19-
- API_URL
20-
- MONGO_URL
21-
- PORT
22-
- SESSION_SECRET
23-
- AWS_ACCESS_KEY
24-
- AWS_SECRET_KEY
25-
- S3_BUCKET
26-
- AWS_REGION
27-
- GITHUB_ID
28-
- GITHUB_SECRET
29-
- MAILGUN_DOMAIN
30-
- MAILGUN_KEY
31-
- EMAIL_SENDER
32-
- EMAIL_VERIFY_SECRET_TOKEN
33-
- S3_BUCKET_URL_BASE
34-
- GG_EXAMPLES_USERNAME
35-
- GG_EXAMPLES_PASS
36-
- GG_EXAMPLES_EMAIL
37-
- GOOGLE_ID
38-
- GOOGLE_SECRET
39-
- EXAMPLE_USER_EMAIL
40-
- EXAMPLE_USER_PASSWORD
41-
- ML5_EXAMPLES_USERNAME
42-
- ML5_EXAMPLES_PASS
43-
- ML5_EXAMPLES_EMAIL
44-
- UI_ACCESS_TOKEN_ENABLED
45-
- UPLOAD_LIMIT
46-
- TRANSLATIONS_ENABLED
18+
- "$PWD/.env"
19+
# environment:
20+
# - API_URL
21+
# - AWS_ACCESS_KEY
22+
# - AWS_REGION
23+
# - AWS_SECRET_KEY
24+
# - EMAIL_SENDER
25+
# - EMAIL_VERIFY_SECRET_TOKEN
26+
# - EXAMPLE_USER_EMAIL
27+
# - EXAMPLE_USER_PASSWORD
28+
# - GG_EXAMPLES_USERNAME
29+
# - GG_EXAMPLES_EMAIL
30+
# - GG_EXAMPLES_PASS
31+
# - GITHUB_ID
32+
# - GITHUB_SECRET
33+
# - GOOGLE_ID
34+
# - GOOGLE_SECRET
35+
# - MAILGUN_DOMAIN
36+
# - MAILGUN_KEY
37+
# - ML5_EXAMPLES_USERNAME
38+
# - ML5_EXAMPLES_EMAIL
39+
# - ML5_EXAMPLES_PASS
40+
# - MOBILE_EMABLED
41+
# - MONGO_URL
42+
# - PORT
43+
# - PREVIEW_PORT
44+
# - EDITOR_URL
45+
# - PREVIEW_URL
46+
# - S3_BUCKET
47+
# - S3_BUCKET_URL_BASE
48+
# - SESSION_SECRET
49+
# - TRANSLATIONS_ENABLED
50+
# - UI_ACCESS_TOKEN_ENABLED
51+
# - UPLOAD_LIMIT
4752
# you can either set this in your .env or as an environment variables
4853
# or here YOU CHOOSE
4954
# - MONGO_URL=mongodb://mongo:27017/p5js-web-editor
@@ -52,6 +57,7 @@ services:
5257
- /opt/node/app/node_modules
5358
ports:
5459
- '8000:8000'
60+
- '8002:8002'
5561
depends_on:
5662
- mongo
5763
volumes:

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
if (process.env.NODE_ENV === 'production') {
22
process.env.webpackAssets = JSON.stringify(require('./dist/static/manifest.json'));
33
require('./dist/server.bundle.js');
4+
require('./dist/previewServer.bundle.js');
45
} else {
56
let parsed = require('dotenv').config();
67
require('@babel/register')({

kubernetes_app.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ spec:
99
serviceName: web-editor-node
1010
servicePort: 8000
1111
---
12+
apiVersion: extensions/v1beta1
13+
kind: Ingress
14+
metadata:
15+
name: preview-editor-ingress
16+
annotations:
17+
# need to make another global static ip
18+
kubernetes.io/ingress.global-static-ip-name: "web-editor-ip"
19+
spec:
20+
backend:
21+
serviceName: web-editor-node
22+
servicePort: 8002
23+
---
1224
apiVersion: v1
1325
kind: Service
1426
metadata:
@@ -23,6 +35,8 @@ spec:
2335
ports:
2436
- port: 8000
2537
targetPort: 8000
38+
- port: 8002
39+
targetPort: 8002
2640
selector:
2741
app: web-editor
2842
---

server/models/collection.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,5 @@ collectionSchema.pre('save', function generateSlug(next) {
5353
return next();
5454
});
5555

56-
export default mongoose.model('Collection', collectionSchema);
56+
export default mongoose.models.Collection ||
57+
mongoose.model('Collection', collectionSchema);

server/models/project.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,5 @@ projectSchema.methods.isSlugUnique = async function isSlugUnique(cb) {
9393
}
9494
};
9595

96-
export default mongoose.model('Project', projectSchema);
96+
export default mongoose.models.Project ||
97+
mongoose.model('Project', projectSchema);

server/models/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,4 @@ userSchema.statics.EmailConfirmation = EmailConfirmationStates;
306306
userSchema.index({ username: 1 }, { collation: { locale: 'en', strength: 2 } });
307307
userSchema.index({ email: 1 }, { collation: { locale: 'en', strength: 2 } });
308308

309-
export default mongoose.model('User', userSchema);
309+
export default mongoose.models.User || mongoose.model('User', userSchema);

server/views/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export function renderIndex() {
3535
window.process.env.MOBILE_ENABLED = ${process.env.MOBILE_ENABLED ? `${process.env.MOBILE_ENABLED}` : undefined};
3636
window.process.env.TRANSLATIONS_ENABLED = ${process.env.TRANSLATIONS_ENABLED === 'true' ? true : false};
3737
window.process.env.PREVIEW_URL = '${process.env.PREVIEW_URL}';
38-
window.process.env.PREVIEW_SCRIPTS_URL = '${process.env.NODE_ENV === 'production' ? `${assetsManifest['/previewScripts.js']}` : '/previewScripts.js'}';
3938
</script>
4039
</head>
4140
<body>

server/views/previewIndex.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ function renderPreviewIndex() {
2424
</head>
2525
<body>
2626
<div id="root" class="root-app">
27-
<script src="/preview-app.js"></script>
2827
</div>
28+
<script src='${
29+
process.env.NODE_ENV === 'production'
30+
? `${assetsManifest['/previewApp.js']}`
31+
: '/previewApp.js'
32+
}'></script>
2933
</body>
3034
</html>
3135
`;

webpack/config.dev.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ if (process.env.NODE_ENV === 'development') {
77
require('dotenv').config();
88
}
99

10-
11-
// react hmr being fucked up has to do with the multiple entries!!! cool.
1210
module.exports = {
1311
mode: 'development',
1412
devtool: 'cheap-module-eval-source-map',
@@ -20,7 +18,7 @@ module.exports = {
2018
'react-hot-loader/patch',
2119
'./client/index.jsx',
2220
],
23-
'preview-app': [
21+
'previewApp': [
2422
'core-js/modules/es6.promise',
2523
'core-js/modules/es6.array.iterator',
2624
'webpack-hot-middleware/client',

0 commit comments

Comments
 (0)