Skip to content

Commit 1f9f1ab

Browse files
committed
feat: serve editor(front-end) with strapi(koa-static)
1 parent ba852c4 commit 1f9f1ab

File tree

10 files changed

+145
-5
lines changed

10 files changed

+145
-5
lines changed

.editorconfig

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[*.{js,jsx,ts,tsx,vue}]
2+
indent_style = space
3+
indent_size = 2
4+
trim_trailing_whitespace = true
5+
insert_final_newline = true

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ pids
9494
logs
9595
results
9696
build
97+
build-editor
9798
node_modules
9899
.node_history
99100
package-lock.json

back-end/h5-api/config/custom.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"myCustomConfiguration": "This configuration is accessible through strapi.config.myCustomConfiguration"
2+
"myCustomConfiguration": "This configuration is accessible through strapi.config.myCustomConfiguration",
3+
"custom": {
4+
"enabled": true
5+
}
36
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"editorStatic": {
3+
"enabled": true
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"editorStatic": {
3+
"enabled": true
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"editorStatic": {
3+
"enabled": true
4+
}
5+
}

back-end/h5-api/config/middleware.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"gzip"
1010
],
1111
"order": [
12-
"Define the middlewares' load order by putting their name in this array is the right order"
12+
"Define the middlewares' load order by putting their name in this array is the right order",
13+
"editorStatic"
1314
],
1415
"after": [
1516
"parser",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* @Author: ly525
3+
* @Date: 2020-01-02 21:50:50
4+
* @LastEditors : ly525
5+
* @LastEditTime : 2020-01-11 00:22:10
6+
* @FilePath: /h5-api/api/work/controllers/Work.js
7+
* @Github: https://github.com/ly525/luban-h5
8+
* @Description:
9+
* serve luban-h5 front-end dist
10+
*
11+
* You will find information here:
12+
* 1. https://github.com/strapi/strapi/issues/3007
13+
* 2. https://stackoverflow.com/questions/55090339/strapi-custom-routes-to-redirect-to-public-directory/55130475#55130475
14+
* 3. https://medium.com/@schalkneethling/automate-package-releases-with-semantic-release-and-commitizen-d7d4c337f04f
15+
* 4. https://strapi.io/documentation/3.0.0-beta.x/concepts/middlewares.html#middlewares
16+
*/
17+
18+
const koaStatic = require('koa-static');
19+
const path = require('path');
20+
21+
module.exports = strapi => {
22+
return {
23+
// eslint-disable-next-line no-unused-vars
24+
initialize: function(cb) {
25+
strapi.router.get(
26+
'/*',
27+
koaStatic(path.resolve('./build-editor'))
28+
);
29+
}
30+
};
31+
};

front-end/h5/vue.config.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
22
* @Author: ly525
33
* @Date: 2019-12-14 22:43:55
4-
* @LastEditors: ly525
5-
* @LastEditTime: 2020-01-05 22:09:02
4+
* @LastEditors : ly525
5+
* @LastEditTime : 2020-01-10 23:37:15
66
* @FilePath: /luban-h5/front-end/h5/vue.config.js
77
* @Github: https://github.com/ly525/luban-h5
88
* @Description: Do not edit
@@ -12,6 +12,7 @@ const path = require('path')
1212
// const isProd = process.env.NODE_ENV === 'production'
1313
const target = 'http://localhost:1337'
1414
const engineOutputDir = path.join(__dirname, '../../back-end/h5-api/public/engine-assets')
15+
const editorBuildOutputDir = path.join(__dirname, '../../back-end/h5-api/build-editor')
1516

1617
let page
1718
switch (process.env.PAGE) {
@@ -28,7 +29,8 @@ switch (process.env.PAGE) {
2829
template: 'public/index.html',
2930
filename: 'index.html',
3031
title: 'Index Page',
31-
outputDir: 'dist'
32+
// outputDir: 'dist'
33+
outputDir: editorBuildOutputDir
3234
// publicPath: isProd ? '/main/' : '/'
3335
}
3436
}

luban-h5.sh

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/sh
2+
3+
###
4+
# @Author: ly525
5+
# @Date: 2020-01-10 22:23:34
6+
# @LastEditors : ly525
7+
# @LastEditTime : 2020-01-10 23:27:59
8+
# @FilePath: /luban-h5/luban-h5.sh
9+
# @Github: https://github.com/ly525/luban-h5
10+
# @Description: Do not edit
11+
# @Copyright 2018 - 2019 luban-h5. All Rights Reserved
12+
###
13+
14+
15+
cur_dir=`pwd`
16+
17+
help_usage() {
18+
cat << EOT
19+
Usage:
20+
$(basename $0) [--help|-h] [init|start|restart|stop]
21+
22+
help Show usage.
23+
24+
init #!en Install dependencies, build front-end && back-end.
25+
#!zh 初始化: 安装依赖并编译前后端
26+
27+
start #!en Start the luban-h5 service(powered by pm2).
28+
#!zh 启动luban-h5, 执行这一步骤之前, 需要执行 ./$(basename $0) init
29+
30+
restart #!en Restart the luban-h5 service.
31+
#!zh 重启luban-h5
32+
33+
stop #!em Build binary packages only.
34+
#!zh 停止luban-h5
35+
36+
e.g.
37+
./luban-h5.sh init
38+
./luban-h5.sh start
39+
./luban-h5.sh stop
40+
EOT
41+
exit
42+
}
43+
44+
45+
luban_h5_init() {
46+
# 到前端目录安装依赖,并编译核心编辑器 + 预览引擎
47+
# #!en compile the core editor and preview engine
48+
cd front-end/h5 && yarn && yarn build
49+
cd ${cur_dir}
50+
51+
# 在后端目录,编译后台管理系统
52+
cd back-end/h5-api && yarn && yarn build
53+
cd ${cur_dir}
54+
}
55+
56+
luban_h5_start() {
57+
cd back-end/h5-api && npx pm2 start --name luban-h5-service server.js
58+
cd ${cur_dir}
59+
}
60+
61+
luban_h5_restart() {
62+
cd back-end/h5-api && npx pm2 restart luban-h5-service
63+
cd ${cur_dir}
64+
}
65+
66+
luban_h5_stop() {
67+
cd back-end/h5-api && npx pm2 stop luban-h5-service
68+
cd ${cur_dir}
69+
}
70+
71+
72+
73+
# Initialization step
74+
action=$1
75+
case "$action" in
76+
init|start|restart|stop)
77+
luban_h5_${action}
78+
;;
79+
*)
80+
help_usage
81+
;;
82+
esac

0 commit comments

Comments
 (0)