Commit 1f9f1abb1c930917bca4bd9181fb24d7d2463f04

Authored by ly525
Committed by 小小鲁班
1 parent ba852c42

feat: serve editor(front-end) with strapi(koa-static)

.editorconfig 0 → 100644
  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
@@ -94,6 +94,7 @@ pids @@ -94,6 +94,7 @@ pids
94 logs 94 logs
95 results 95 results
96 build 96 build
  97 +build-editor
97 node_modules 98 node_modules
98 .node_history 99 .node_history
99 package-lock.json 100 package-lock.json
back-end/h5-api/config/custom.json
1 { 1 {
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 + }
3 } 6 }
back-end/h5-api/config/environments/development/middleware.json 0 → 100644
  1 +{
  2 + "editorStatic": {
  3 + "enabled": true
  4 + }
  5 +}
0 \ No newline at end of file 6 \ No newline at end of file
back-end/h5-api/config/environments/production/middleware.json 0 → 100644
  1 +{
  2 + "editorStatic": {
  3 + "enabled": true
  4 + }
  5 +}
0 \ No newline at end of file 6 \ No newline at end of file
back-end/h5-api/config/environments/staging/middleware.json 0 → 100644
  1 +{
  2 + "editorStatic": {
  3 + "enabled": true
  4 + }
  5 +}
0 \ No newline at end of file 6 \ No newline at end of file
back-end/h5-api/config/middleware.json
@@ -9,7 +9,8 @@ @@ -9,7 +9,8 @@
9 "gzip" 9 "gzip"
10 ], 10 ],
11 "order": [ 11 "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"
13 ], 14 ],
14 "after": [ 15 "after": [
15 "parser", 16 "parser",
back-end/h5-api/middlewares/editorStatic/index.js 0 → 100644
  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 +};
0 \ No newline at end of file 32 \ No newline at end of file
front-end/h5/vue.config.js
1 /* 1 /*
2 * @Author: ly525 2 * @Author: ly525
3 * @Date: 2019-12-14 22:43:55 3 * @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
6 * @FilePath: /luban-h5/front-end/h5/vue.config.js 6 * @FilePath: /luban-h5/front-end/h5/vue.config.js
7 * @Github: https://github.com/ly525/luban-h5 7 * @Github: https://github.com/ly525/luban-h5
8 * @Description: Do not edit 8 * @Description: Do not edit
@@ -12,6 +12,7 @@ const path = require('path') @@ -12,6 +12,7 @@ const path = require('path')
12 // const isProd = process.env.NODE_ENV === 'production' 12 // const isProd = process.env.NODE_ENV === 'production'
13 const target = 'http://localhost:1337' 13 const target = 'http://localhost:1337'
14 const engineOutputDir = path.join(__dirname, '../../back-end/h5-api/public/engine-assets') 14 const engineOutputDir = path.join(__dirname, '../../back-end/h5-api/public/engine-assets')
  15 +const editorBuildOutputDir = path.join(__dirname, '../../back-end/h5-api/build-editor')
15 16
16 let page 17 let page
17 switch (process.env.PAGE) { 18 switch (process.env.PAGE) {
@@ -28,7 +29,8 @@ switch (process.env.PAGE) { @@ -28,7 +29,8 @@ switch (process.env.PAGE) {
28 template: 'public/index.html', 29 template: 'public/index.html',
29 filename: 'index.html', 30 filename: 'index.html',
30 title: 'Index Page', 31 title: 'Index Page',
31 - outputDir: 'dist' 32 + // outputDir: 'dist'
  33 + outputDir: editorBuildOutputDir
32 // publicPath: isProd ? '/main/' : '/' 34 // publicPath: isProd ? '/main/' : '/'
33 } 35 }
34 } 36 }
luban-h5.sh 0 → 100755
  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 \ No newline at end of file 83 \ No newline at end of file