Skip to content

Commit 377c43b

Browse files
committed
Run backend and frontend
1 parent 458f031 commit 377c43b

File tree

7 files changed

+625
-577
lines changed

7 files changed

+625
-577
lines changed

Diff for: config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
22
tokenSecret: 'SECRET',
3-
wordPressUrl: 'http://localhost:8888/wordpress',
3+
wordPressUrl: 'https://orionhive.com',
44
wordPressRestNameSpace: '/wp-json/wp/v2/rae'
55
};

Diff for: index.pug

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
html
2+
head
3+
meta(charset="UTF-8")
4+
meta(name="viewport", content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0")
5+
link(rel="stylesheet", href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css")
6+
link(rel="stylesheet", href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css")
7+
link(rel="stylesheet", href="static/bundle.css")
8+
|
9+
body
10+
div(id="root")
11+
script(src="static/bundle.js")

Diff for: package-lock.json

+521-552
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+14-11
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
"description": ":fire: This is a workshop for learning how to build React Applications.",
55
"main": "index.js",
66
"scripts": {
7+
"start": "NODE_ENV=development nodemon server.js",
78
"webpack-dev-server": "webpack-dev-server",
89
"dev:client": "webpack-dev-server --mode=development",
910
"dev:server": "nodemon server.js",
10-
"start": "concurrently \"npm run dev:client\" \"npm run dev:server\"",
11+
"dev": "concurrently \"npm run dev:client\" \"npm run dev:server\"",
1112
"prod": "webpack --mode=production"
1213
},
1314
"repository": {
@@ -22,18 +23,27 @@
2223
},
2324
"homepage": "https://github.com/imranhsayed/react-workshop#readme",
2425
"dependencies": {
26+
"@babel/core": "^7.4.3",
27+
"@babel/plugin-proposal-class-properties": "^7.4.0",
28+
"@babel/preset-env": "^7.4.3",
29+
"@babel/preset-react": "^7.0.0",
2530
"@reach/router": "^1.2.1",
2631
"axios": "^0.18.0",
32+
"babel-loader": "^8.0.5",
2733
"body-parser": "^1.19.0",
2834
"concurrently": "^4.1.0",
2935
"cors": "^2.8.5",
3036
"css-loader": "^2.1.1",
3137
"express": "^4.17.0",
3238
"file-loader": "^3.0.1",
39+
"html-webpack-plugin": "^3.2.0",
3340
"image-webpack-loader": "^4.6.0",
3441
"jsonwebtoken": "^8.5.1",
42+
"mini-css-extract-plugin": "^0.6.0",
3543
"moment": "^2.24.0",
3644
"nodemon": "^1.19.0",
45+
"path": "^0.12.7",
46+
"pug": "^2.0.3",
3747
"qs": "^6.7.0",
3848
"react": "^16.8.6",
3949
"react-dom": "^16.8.6",
@@ -42,16 +52,9 @@
4252
"react-render-html": "^0.6.0",
4353
"style-loader": "^0.23.1",
4454
"url-loader": "^1.1.2",
45-
"webpack-dev-server": "^3.4.1",
46-
"@babel/core": "^7.4.3",
47-
"@babel/plugin-proposal-class-properties": "^7.4.0",
48-
"@babel/preset-env": "^7.4.3",
49-
"@babel/preset-react": "^7.0.0",
50-
"babel-loader": "^8.0.5",
51-
"html-webpack-plugin": "^3.2.0",
52-
"path": "^0.12.7",
53-
"webpack": "^4.29.6",
54-
"webpack-cli": "^3.3.0"
55+
"webpack": "^4.29.6",
56+
"webpack-cli": "^3.3.0",
57+
"webpack-dev-server": "^3.4.1"
5558
},
5659
"engines": {
5760
"node": "8.12.0"

Diff for: server.js

+46-2
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,44 @@ const jwt = require('jsonwebtoken');
44
const bodyParser = require('body-parser');
55
const config = require( './config' );
66
const axios = require( 'axios' );
7+
const webpack = require('webpack');
8+
const webpackDevMiddleware = require('webpack-dev-middleware');
9+
const webpackConfig = require('./webpack.config');
10+
const path = require('path')
711

8-
const wordPressRestUrl = `${config.wordPressUrl}${config.wordPressRestNameSpace}`;
12+
const wordPressRestUrl = `${config.wordPressUrl}/${config.wordPressRestNameSpace}`;
13+
14+
console.log(wordPressRestUrl, 'wordpressurl')
915

1016
const app = express();
1117
app.use( cors() );
1218

19+
// Setting Paths
20+
app.use('/static', express.static(path.join(__dirname, '/')));
21+
22+
// Setting views of the app
23+
app.set('views', path.join(__dirname, './'));
24+
app.set('view engine', 'pug');
25+
1326
// Parse application/x-www-form-urlencoded
1427
app.use( bodyParser.urlencoded( { extended: false } ) );
1528

1629
// Parse application/json
1730
app.use(bodyParser.json());
1831

32+
// Adding webpack build
33+
// Middleware of webpack
34+
if (process.env.NODE_ENV === 'development') {
35+
console.log('in webpack hot middleware');
36+
const compiler = webpack(webpackConfig);
37+
38+
app.use(webpackDevMiddleware(compiler, {
39+
noInfo: true,
40+
publicPath: webpackConfig.output.publicPath,
41+
}));
42+
}
43+
44+
1945
/**
2046
* Sign in user
2147
*
@@ -31,7 +57,6 @@ app.post( '/sign-in', ( req, res ) => {
3157
// Make a login request.
3258
axios.post( `${wordPressRestUrl}/user/login`, req.body )
3359
.then( response => {
34-
3560
res.json( {
3661
success: true,
3762
status: 200,
@@ -84,4 +109,23 @@ app.post( '/create-post', ( req, res ) => {
84109
});
85110
} );
86111

112+
app.get('/', (req, res) => {
113+
res.render('index')
114+
})
115+
116+
app.get('/login', (req, res) => {
117+
res.render('index')
118+
})
119+
120+
app.get('/dashboard/:userName', (req, res) => {
121+
res.render('index')
122+
})
123+
124+
app.get('/post/:id', (req, res) => {
125+
res.render('index')
126+
})
127+
128+
129+
130+
87131
app.listen( 5000, () => console.log( 'Listening on port 5000' ) );

Diff for: src/components/Home.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Home extends React.Component {
2323
});
2424

2525
componentDidMount() {
26-
const wordPressSiteURL = 'http://localhost:8888/wordpress';
26+
const wordPressSiteURL = 'https://orionhive.com';
2727
this.setState( { loading: true }, () => {
2828
axios.get( `${wordPressSiteURL}/wp-json/wp/v2/posts/` )
2929
.then( res => {

Diff for: webpack.config.js

+31-10
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,59 @@
11
const HtmlWebPackPlugin = require( 'html-webpack-plugin' );
22
const path = require( 'path' );
3+
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
4+
const webpack = require('webpack')
5+
36
module.exports = {
47
context: __dirname,
58
entry: './src/index.js',
69
output: {
7-
path: path.resolve( __dirname, 'dist' ),
8-
filename: 'main.js',
9-
publicPath: "/"
10+
filename: 'bundle.js',
11+
path: __dirname + '/dist/bundle/',
12+
publicPath: '/static/'
1013
},
1114
devServer: {
1215
historyApiFallback: true
1316
},
1417
module: {
1518
rules: [
1619
{
17-
test: /\.js$/,
18-
use: 'babel-loader',
20+
test: /\.js?$/,
21+
exclude: /node_modules/,
22+
use: { loader: 'babel-loader' },
1923
},
2024
{
2125
test: /\.css$/,
22-
use: ['style-loader', 'css-loader'],
26+
use: [
27+
{ loader: MiniCssExtractPlugin.loader },
28+
{
29+
loader: 'css-loader',
30+
},
31+
]
2332
},
2433
{
25-
test: /\.(png|jp?g|svg|gif)$/,
26-
use: [{
27-
loader: "file-loader",
28-
}]
34+
test: /\.(png|jpg|gif)$/,
35+
use: [
36+
{
37+
loader: 'file-loader',
38+
options: {}
39+
}
40+
]
2941
}
3042
]
3143
},
3244
plugins: [
3345
new HtmlWebPackPlugin({
3446
template: path.resolve( __dirname, 'public/index.html' ),
3547
filename: 'index.html'
48+
}),
49+
new webpack.HotModuleReplacementPlugin(),
50+
new webpack.DefinePlugin({
51+
'process.env': {
52+
'NODE_ENV': JSON.stringify('development')
53+
}
54+
}),
55+
new MiniCssExtractPlugin({
56+
filename: "bundle.css",
3657
})
3758
]
3859
};

0 commit comments

Comments
 (0)