Skip to content

Commit 53982e0

Browse files
committed
Adding production testing server and helper build-serve npm script
1 parent 9eb0caf commit 53982e0

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

package-lock.json

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

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"start": "ng serve",
77
"start:ar": "ng serve --configuration ar",
88
"build": "ng build",
9+
"build-serve": "ng build && node serve-prod-test.js",
910
"watch": "ng build --watch --configuration development",
1011
"test": "ng test",
1112
"i18n:extract": "ng extract-i18n --output-path src/locale"
@@ -32,6 +33,7 @@
3233
"@types/jasmine": "~3.10.0",
3334
"@types/node": "^12.11.1",
3435
"autoprefixer": "^10.4.7",
36+
"express": "^4.18.1",
3537
"jasmine-core": "~4.0.0",
3638
"karma": "~6.3.0",
3739
"karma-chrome-launcher": "~3.1.0",

serve-prod-test.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const path = require('path');
2+
const express = require('express');
3+
4+
const port = 8080;
5+
const rootDir = path.join(__dirname, 'dist/azcadea');
6+
7+
const locales = ['en-CA', 'ar'];
8+
const defaultLocale = 'en-CA';
9+
10+
const server = express();
11+
12+
server.use(express.static(rootDir));
13+
14+
locales.forEach((locale) => {
15+
server.get(`/${locale}/*`, async (req, res) => {
16+
res.sendFile(
17+
path.resolve(rootDir, locale, 'index.html')
18+
);
19+
});
20+
});
21+
22+
server.get('/', (req, res) =>
23+
res.redirect(`/${defaultLocale}`)
24+
);
25+
26+
server.listen(port, () =>
27+
console.log(`App running at port ${port}…`)
28+
);

0 commit comments

Comments
 (0)