Skip to content

Commit 82671ae

Browse files
committed
improve server code
1 parent 174ad1d commit 82671ae

File tree

5 files changed

+148
-104
lines changed

5 files changed

+148
-104
lines changed

.github/clean.config.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const path = require("path");
2+
const fs = require("fs");
3+
4+
const filePath = path.join(process.cwd(), "config.json");
5+
6+
try {
7+
// Read the file
8+
const jsonData = JSON.parse(fs.readFileSync(filePath, "utf8"));
9+
10+
// Delete the fields
11+
delete jsonData.ngx;
12+
delete jsonData.wjst;
13+
14+
// Write the updated JSON back to the file
15+
fs.writeFileSync(filePath, JSON.stringify(jsonData, null, 2));
16+
17+
console.log('Fields "ngx" and "wjst" have been deleted successfully.');
18+
} catch (error) {
19+
console.error("Error processing file:", error);
20+
}

.github/workflows/ngx-default.yml

+36-36
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
name: Sync Angular client to ngx-default
22

33
on:
4-
push:
5-
paths:
6-
- 'client/**' # Trigger only on changes in the angular folder
4+
push:
5+
paths:
6+
- "client/**" # Trigger only on changes in the angular folder
77

88
jobs:
9-
sync-angular:
10-
runs-on: ubuntu-latest
9+
sync-angular:
10+
runs-on: ubuntu-latest
1111

12-
steps:
13-
- name: Checkout source repository
14-
uses: actions/checkout@v3
12+
steps:
13+
- name: Checkout source repository
14+
uses: actions/checkout@v3
1515

16-
- name: Set up SSH
17-
env:
18-
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
19-
run: |
20-
mkdir -p ~/.ssh
21-
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
22-
chmod 600 ~/.ssh/id_rsa
23-
ssh-keyscan github.com >> ~/.ssh/known_hosts
16+
- name: Set up SSH
17+
env:
18+
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
19+
run: |
20+
mkdir -p ~/.ssh
21+
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
22+
chmod 600 ~/.ssh/id_rsa
23+
ssh-keyscan github.com >> ~/.ssh/known_hosts
2424
25-
- name: Sync Angular folder to ngx-default
26-
run: |
27-
git config --global user.name "github-actions[bot]"
28-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
29-
git clone [email protected]:WebArtWork/ngx-default.git ngx-default
30-
rm -rf ngx-default/*
31-
cp -r client/* ngx-default/
32-
cd ngx-default
33-
echo "ngx.webart.work" > CNAME
34-
sed -i "s/admins.guard';/admins.guard';\\nimport { HashLocationStrategy, LocationStrategy } from '@angular\\/common';/g" src/app/app.module.ts
35-
sed -i "s|/\* providers \*/|/* providers */\\n\t\t{ provide: LocationStrategy, useClass: HashLocationStrategy },|g" src/app/app.module.ts
36-
sed -i "s/url: ''/url: 'https:\/\/webart.work'/g" src/environments/environment.prod.ts
37-
sed -i "s/[email protected]/[email protected]/g" src/app/pages/guest/sign/sign.component.ts
38-
git add .
39-
git commit -m "Update Angular files from source repository" || echo "No changes to commit"
40-
git push --force
25+
- name: Sync Angular folder to ngx-default
26+
run: |
27+
git config --global user.name "github-actions[bot]"
28+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
29+
git clone [email protected]:WebArtWork/ngx-default.git ngx-default
30+
rm -rf ngx-default/*
31+
cp -r client/* ngx-default/
32+
cd ngx-default
33+
echo "ngx.webart.work" > CNAME
34+
sed -i "s/admins.guard';/admins.guard';\\nimport { HashLocationStrategy, LocationStrategy } from '@angular\\/common';/g" src/app/app.module.ts
35+
sed -i "s|/\* providers \*/|/* providers */\\n\t\t{ provide: LocationStrategy, useClass: HashLocationStrategy },|g" src/app/app.module.ts
36+
sed -i "s/url: ''/url: 'https:\/\/webart.work'/g" src/environments/environment.prod.ts
37+
sed -i "s/[email protected]/[email protected]/g" src/environments/environment.prod.ts
38+
git add .
39+
git commit -m "Update Angular files from source repository" || echo "No changes to commit"
40+
git push --force
4141
42-
- name: Clean up SSH
43-
run: |
44-
rm -f ~/.ssh/id_rsa
45-
rm -f ~/.ssh/known_hosts
42+
- name: Clean up SSH
43+
run: |
44+
rm -f ~/.ssh/id_rsa
45+
rm -f ~/.ssh/known_hosts

.github/workflows/waw-default.yml

+49-47
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,58 @@
11
name: Sync waw default project to waw-default
22

33
on:
4-
push:
5-
paths:
6-
- 'server/**' # Trigger only on changes in the server folder
4+
push:
5+
paths:
6+
- "server/**" # Trigger only on changes in the server folder
77

88
jobs:
9-
sync-waw:
10-
runs-on: ubuntu-latest
9+
sync-waw:
10+
runs-on: ubuntu-latest
1111

12-
steps:
13-
- name: Checkout source repository
14-
uses: actions/checkout@v3
12+
steps:
13+
- name: Checkout source repository
14+
uses: actions/checkout@v3
1515

16-
- name: Set up SSH
17-
env:
18-
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
19-
run: |
20-
mkdir -p ~/.ssh
21-
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
22-
chmod 600 ~/.ssh/id_rsa
23-
ssh-keyscan github.com >> ~/.ssh/known_hosts
16+
- name: Set up SSH
17+
env:
18+
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
19+
run: |
20+
mkdir -p ~/.ssh
21+
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
22+
chmod 600 ~/.ssh/id_rsa
23+
ssh-keyscan github.com >> ~/.ssh/known_hosts
2424
25-
- name: Sync waw default folder to waw-default
26-
run: |
27-
git config --global user.name "github-actions[bot]"
28-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
29-
git clone [email protected]:WebArtWork/waw-default.git waw-default
30-
rm -rf waw-default/*
31-
cp -r server/* waw-default/
32-
cd waw-default
33-
git add .
34-
git commit -m "Update files from source repository" || echo "No changes to commit"
35-
git push --force
36-
cd ..
37-
git clone [email protected]:WebArtWork/vue-platform.git vue-platform
38-
rm -rf vue-platform/server/*
39-
cp -r server/* vue-platform/server/
40-
cd vue-platform
41-
git add .
42-
git commit -m "Update files from source repository" || echo "No changes to commit"
43-
git push --force
44-
cd ..
45-
git clone [email protected]:WebArtWork/react-platform.git react-platform
46-
rm -rf react-platform/server/*
47-
cp -r server/* react-platform/server/
48-
cd react-platform
49-
git add .
50-
git commit -m "Update files from source repository" || echo "No changes to commit"
51-
git push --force
25+
- name: Sync waw default folder to waw-default
26+
run: |
27+
git config --global user.name "github-actions[bot]"
28+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
29+
git clone [email protected]:WebArtWork/waw-default.git waw-default
30+
rm -rf waw-default/*
31+
cp -r server/* waw-default/
32+
node .github/clean.config.js
33+
cp -r config.json waw-default/config.json
34+
cd waw-default
35+
git add .
36+
git commit -m "Update files from source repository" || echo "No changes to commit"
37+
git push --force
38+
cd ..
39+
git clone [email protected]:WebArtWork/vue-platform.git vue-platform
40+
rm -rf vue-platform/server/*
41+
cp -r server/* vue-platform/server/
42+
cd vue-platform
43+
git add .
44+
git commit -m "Update files from source repository" || echo "No changes to commit"
45+
git push --force
46+
cd ..
47+
git clone [email protected]:WebArtWork/react-platform.git react-platform
48+
rm -rf react-platform/server/*
49+
cp -r server/* react-platform/server/
50+
cd react-platform
51+
git add .
52+
git commit -m "Update files from source repository" || echo "No changes to commit"
53+
git push --force
5254
53-
- name: Clean up SSH
54-
run: |
55-
rm -f ~/.ssh/id_rsa
56-
rm -f ~/.ssh/known_hosts
55+
- name: Clean up SSH
56+
run: |
57+
rm -f ~/.ssh/id_rsa
58+
rm -f ~/.ssh/known_hosts

config.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"ngx": {
3333
"apps": [
3434
{
35-
"path": "/client"
35+
"path": "/client",
36+
"dist": "/client/dist/app/browser"
3637
}
3738
]
3839
},

server/user/user.api.js

+41-20
Original file line numberDiff line numberDiff line change
@@ -161,26 +161,47 @@ module.exports = function (waw) {
161161
);
162162
};
163163

164-
waw.api({
165-
app: path.join(process.cwd(), "client", "dist", "app", "browser"),
166-
});
167-
const templatePath = path.join(process.cwd(), "template");
168-
waw.api({
169-
template: {
170-
path: templatePath,
171-
prefix: "/wjst-default",
172-
pages: "index",
173-
},
174-
page: {
175-
"/": (req, res) => {
176-
res.send(
177-
waw.render(path.join(templatePath, "dist", "index.html"), {
178-
base: "/wjst-default/",
179-
})
180-
);
181-
},
182-
},
183-
});
164+
if (
165+
waw.config.ngx &&
166+
Array.isArray(waw.config.ngx.apps) &&
167+
waw.config.ngx.apps.length
168+
) {
169+
for (const app of waw.config.ngx.apps) {
170+
waw.api({
171+
app: path.join(process.cwd(), app.dist),
172+
});
173+
}
174+
}
175+
176+
if (
177+
waw.config.wjst &&
178+
Array.isArray(waw.config.wjst.templates) &&
179+
waw.config.wjst.templates.length
180+
) {
181+
for (const template of waw.config.ngx.templates) {
182+
const templatePath = path.join(process.cwd(), template.path);
183+
184+
waw.api({
185+
template: {
186+
path: templatePath,
187+
prefix: template.prefix,
188+
pages: template.pages,
189+
},
190+
page: {
191+
"/": (req, res) => {
192+
res.send(
193+
waw.render(
194+
path.join(templatePath, "dist", "index.html"),
195+
{
196+
base: "/wjst-default/",
197+
}
198+
)
199+
);
200+
},
201+
},
202+
});
203+
}
204+
}
184205

185206
waw.api({
186207
router: "/api/user",

0 commit comments

Comments
 (0)