Skip to content

Commit 06a5711

Browse files
authored
Video-38-Add-Build-Scripts (#38)
1 parent 134d3a1 commit 06a5711

4 files changed

Lines changed: 10 additions & 1 deletion

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ package-lock.json
3434
yarn-lock.json
3535
frontend/package-lock.json
3636
frontend/yarn-lock.json
37+
frontend/main.js

backend/server.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import express from 'express';
22
import cors from 'cors';
33
import mongoose from 'mongoose';
44
import bodyParser from 'body-parser';
5+
import path from 'path';
56
import config from './config';
67
import userRouter from './routers/userRouter';
78
import orderRouter from './routers/orderRouter';
@@ -30,7 +31,11 @@ app.use('/api/orders', orderRouter);
3031
app.get('/api/paypal/clientId', (req, res) => {
3132
res.send({ clientId: config.PAYPAL_CLIENT_ID });
3233
});
33-
34+
app.use('/uploads', express.static(path.join(__dirname, '/../uploads')));
35+
app.use(express.static(path.join(__dirname, '/../frontend')));
36+
app.get('*', (req, res) => {
37+
res.sendFile(path.join(__dirname, '/../frontend/index.html'));
38+
});
3439
app.use((err, req, res, next) => {
3540
const status = err.name && err.name === 'ValidationError' ? 400 : 500;
3641
res.status(status).send({ message: err.message });

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"start": "webpack-dev-server --watch-content-base --open",
8+
"build": "webpack --mode=production --output ./main.js",
89
"test": "echo \"Error: no test specified\" && exit 1"
910
},
1011
"author": "",

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"main": "index.js",
66
"scripts": {
77
"start": "nodemon --watch backend --exec babel-node backend/server.js",
8+
"build": "rm -rf dest && babel backend -d dist",
9+
"serve": "node dist/server.js",
810
"test": "echo \"Error: no test specified\" && exit 1"
911
},
1012
"repository": {

0 commit comments

Comments
 (0)