Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"version": "1.0.0",
"description": "",
"main": "index.js",
"engines": { "node": ">=14.15.0"},
"engines": {
"node": ">=14.15.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server",
Expand Down
10 changes: 6 additions & 4 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="service1"></div>
<div id="service2"></div>
<div style="display: flex; flex-direction: row; align-items: center;" ></div>
<div style="float: left;" id="service1"></div>
<div style="float: right;" id="service2"></div>
</div>
<div id="service3"></div>
<div id="service4"></div>
<div style="float: left;" id="service4"></div>
<script src="bundles/service1.js"></script>
<script src="bundles/service2.js"></script>
<script src="bundles/service3.js"></script>
<script src="bundles/service4.js"></script>
<script src="bundles/service4.js"></script>
</body>
</html>
22 changes: 11 additions & 11 deletions server/config/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@

module.exports = {
service1: {
api: 'FIX_ME',
api: '/*/:id/photos',
url: 'http://localhost:3001',
bundle: 'app.js',
bundle: '/photos/:id/bundle.js'
},
service2: {
api: 'FIX_ME',
url: 'http://localhost:3002',
bundle: 'app.js',
api: '/*/:id/checkout',
url: 'http://localhost:3005',
bundle: '/checkout/:id/bundle.js',
},
service3: {
api: 'FIX_ME',
api: '/ctl',
url: 'http://localhost:3003',
bundle: 'app.js',
bundle: 'bundle.js',
},
service4: {
api: 'FIX_ME',
url: 'http://localhost:3004',
bundle: 'app.js',
},
api: '/*/:id/reviews',
url: 'http://localhost:8000',
bundle: '/reviews/:id/bundle.js'
}
};
2 changes: 1 addition & 1 deletion server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ const server = require('./server.js');
const PORT = 3000 || process.env.PORT;

server.listen(PORT, () => {
console.log(`Server running on localhost:${PORT}`);
console.log(`Server running on http://localhost:${PORT}/products/1`);
});
2 changes: 1 addition & 1 deletion server/router/api.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { Router } = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
const {
service1, service2, service3, service4,
service1, service2, service3, service4
} = require('../config/services.js');

const router = Router();
Expand Down
10 changes: 5 additions & 5 deletions server/router/bundles.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
const { Router } = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
const {
service1, service2, service3, service4,
service1, service2, service3, service4
} = require('../config/services.js');

const router = Router();

router.use('/service1.js', createProxyMiddleware({
target: service1.url,
pathRewrite: {
'^/bundles/service1.js': service1.bundle,
'^.*': service1.bundle,
},
changeOrigin: true,
}));

router.use('/service2.js', createProxyMiddleware({
target: service2.url,
pathRewrite: {
'^/bundles/service2.js': service2.bundle,
'^.*': service2.bundle,
},
changeOrigin: true,
}));

router.use('/service3.js', createProxyMiddleware({
target: service3.url,
pathRewrite: {
'^/bundles/service3.js': service3.bundle,
'^.*': service3.bundle,
},
changeOrigin: true,
}));

router.use('/service4.js', createProxyMiddleware({
target: service4.url,
pathRewrite: {
'^/bundles/service4.js': service4.bundle,
'^.*': service4.bundle,
},
changeOrigin: true,
}));
Expand Down
7 changes: 4 additions & 3 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ const PUBLIC_DIR = path.resolve(__dirname, '..', 'public');
const app = express();

app.use(morgan('dev'));
app.use(express.static(PUBLIC_DIR));
app.use('/products/:id', express.static(PUBLIC_DIR));
// app.use('/:id', express.static(PUBLIC_DIR));

// Handling asset requests for webpack bundles by passing off requests to the bundles router
app.use('/bundles', router.bundles);
app.use('/products/:id/bundles', router.bundles);
// Handling AJAX requests to the API by passing off requests to the api router
app.use('/api', router.api);
app.use('/', router.api);

module.exports = app;