Commit c7b51f46 authored by 郭志伟's avatar 郭志伟

Merge branch 'feat/apollo' into 'master'

Feat/apollo

See merge request !18
parents a3a30c48 e5855e5e
...@@ -17,6 +17,8 @@ app/**/*.js ...@@ -17,6 +17,8 @@ app/**/*.js
config/plugin.local.js config/plugin.local.js
config/plugin.js config/plugin.js
config/config.*.js config/config.*.js
config/apollo.json
config/apollo.ssr.json
index.js index.js
config/manifest.json config/manifest.json
app/view/* app/view/*
......
import { Controller, Context } from 'egg'; import { Controller, Context } from 'egg';
import * as path from 'path';
export default class ActivityController extends Controller { export default class ActivityController extends Controller {
public async home(ctx: Context) { public async home(ctx: Context) {
...@@ -9,7 +9,11 @@ export default class ActivityController extends Controller { ...@@ -9,7 +9,11 @@ export default class ActivityController extends Controller {
ctx.logger.info('请求redis成功 key: %j', redisKey); ctx.logger.info('请求redis成功 key: %j', redisKey);
} }
if (!body) { if (!body) {
body = await ctx.renderView('activity.js', { url: ctx.url }); let apollo = {};
if (process.env.NODE_ENV === 'production' && process.env.EGG_SERVER_ENV === 'sit') {
apollo = ctx.app.config.apollo || {};
}
body = await ctx.renderView('activity.js', { url: ctx.url, apollo });
await ctx.service.redis.set(redisKey, body); await ctx.service.redis.set(redisKey, body);
} }
ctx.body = body; ctx.body = body;
......
module.exports = { module.exports = {
// Sentry options are required // Sentry options are required
organization: 'sentry', organization: 'sentry',
project: 'quantum-blocks', project: 'quantum-blocks-h5',
apiKey: '2e7e0678d81d4542b09cdbc35812f1cbb07a4993cd13435ba49d9511be11ec95', apiKey: '2e7e0678d81d4542b09cdbc35812f1cbb07a4993cd13435ba49d9511be11ec95',
// Release version name/hash is required // Release version name/hash is required
release: 'quantum-blocks@0.0.1', release: 'quantum-blocks-h5@0.0.1',
baseSentryURL: 'http://sentry.quantgroups.com/api/0', baseSentryURL: 'https://sentry.quantgroups.com/api/0',
deleteAfterCompile: true, deleteAfterCompile: true,
include: /js\//, // 只上传js和map文件 include: /js\//, // 只上传js和map文件
ignore: ['node_modules'], ignore: ['node_modules'],
......
...@@ -3,6 +3,6 @@ import config from '../config'; ...@@ -3,6 +3,6 @@ import config from '../config';
export default { export default {
getPageById(params) { getPageById(params) {
return http.get(`${config.apiHost}editor/get/${params.pageId}`); return http.get(`${config.apiHost}/editor/get/${params.pageId}`);
} }
}; };
\ No newline at end of file
...@@ -11,7 +11,7 @@ import lazyload from '@qg/cherry-ui/src/lazyload/index'; ...@@ -11,7 +11,7 @@ import lazyload from '@qg/cherry-ui/src/lazyload/index';
// 初始化sentry // 初始化sentry
if (process.env.SENTRY_ENV !== 'test' && process.env.NODE_ENV === 'production') { if (process.env.SENTRY_ENV !== 'test' && process.env.NODE_ENV === 'production') {
Raven.config('https://0785298052fd46128e201f30ca649102@sentry.q-gp.com/64', { Raven.config('https://00ea2b4a57c94071a8d56f4548a42de2@sentry.quantgroups.com/66', {
release, release,
environment: 'production' environment: 'production'
}) })
......
...@@ -3,7 +3,7 @@ const protocol = EASY_ENV_IS_BROWSER ? window.location.protocol : 'http'; ...@@ -3,7 +3,7 @@ const protocol = EASY_ENV_IS_BROWSER ? window.location.protocol : 'http';
export default { export default {
// apiHost: `http://localhost:7001/`, // apiHost: `http://localhost:7001/`,
// apiHost: `http://192.168.28.199:7001/`, // apiHost: `http://192.168.28.199:7001/`,
apiHost: 'https://quantum-blocks-vcc2.liangkebang.net/', apiHost: 'https://quantum-blocks-vcc2.liangkebang.net',
shenceUrl: `${protocol}//bn.xyqb.com/sa?project=default`, shenceUrl: `${protocol}//bn.xyqb.com/sa?project=default`,
// opapiHost: `https://opapi-vcc2.liangkebang.net`, // opapiHost: `https://opapi-vcc2.liangkebang.net`,
kdspHost: 'https://kdsp-api-vcc2.liangkebang.net', kdspHost: 'https://kdsp-api-vcc2.liangkebang.net',
......
...@@ -3,4 +3,4 @@ import dev from './dev.config'; ...@@ -3,4 +3,4 @@ import dev from './dev.config';
import test from './test.config'; import test from './test.config';
// export default process.env.NODE_ENV === 'test' ? test : process.env.NODE_ENV === 'production' ? prod : dev; // export default process.env.NODE_ENV === 'test' ? test : process.env.NODE_ENV === 'production' ? prod : dev;
export default process.env.SENTRY_ENV ? test : process.env.NODE_ENV === 'production' ? prod : dev; export default process.env.SENTRY_ENV ? test : process.env.NODE_ENV === 'production' ? prod : dev;
const protocol = EASY_ENV_IS_BROWSER ? window.location.protocol : 'https'; const protocol = EASY_ENV_IS_BROWSER ? window.location.protocol : 'https';
export default { const hostMap = {
apiHost: `https://quantum-blocks.q-gp.com/`, apiHost: `${protocol}//quantum-blocks.q-gp.com`,
shenceUrl: `${protocol}//bn.xyqb.com/sa?project=production`, shenceUrl: `${protocol}//bn.xyqb.com/sa?project=production`,
// opapiHost: `${protocol}//opapi.q-gp.com`,
test: false test: false
}; };
export default hostMap;
import apolloSsr from '../../../config/apollo.ssr.json';
const protocol = EASY_ENV_IS_BROWSER ? window.location.protocol : 'https'; const protocol = EASY_ENV_IS_BROWSER ? window.location.protocol : 'https';
export default { const hostMap = {
apiHost: `https://quantum-blocks-test1.liangkebang.net/`, apiHost: `${protocol}//quantum-blocks-test1.liangkebang.net`,
// opApiHost: 'https://opapi-test1.liangkebang.net',
shenceUrl: `${protocol}//bn.xyqb.com/sa?project=default`, shenceUrl: `${protocol}//bn.xyqb.com/sa?project=default`,
test: true test: true
}; };
if (EASY_ENV_IS_BROWSER) {
const apolloWin = window.apollo || window.__INITIAL_STATE__.apollo;
if (apolloWin) {
for (const key in apolloWin) {
if (apolloWin[key]) {
hostMap[key] = apolloWin[key];
}
}
}
}
if (EASY_ENV_IS_NODE) {
if (apolloSsr) {
for (const key in apolloSsr) {
if (apolloSsr[key]) {
hostMap[key] = apolloSsr[key];
}
}
}
}
export default hostMap;
declare module "*.json" {
const value: any;
export default value;
}
\ No newline at end of file
import Vue from 'vue'; import Vue from 'vue';
import { sync } from 'vuex-router-sync'; import { sync } from 'vuex-router-sync';
import initService from '@/service/init.service'; import initService from '@/service/init.service';
export default class App { export default class App {
config: any; config: any;
constructor(config) { constructor(config) {
...@@ -70,14 +69,13 @@ export default class App { ...@@ -70,14 +69,13 @@ export default class App {
server() { server() {
return context => { return context => {
// console.log('server', context.state);
const vm = this.create(context.state); const vm = this.create(context.state);
const { store, router } = vm; const { store, router } = vm;
router.push(context.state.url); router.push(context.state.url);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
router.onReady(() => { router.onReady(() => {
this.fetch(vm).then(() => { this.fetch(vm).then(() => {
context.state = store.state; context.state = {...store.state, apollo: context.state.apollo};
return resolve(new Vue(vm)); return resolve(new Vue(vm));
}); });
}); });
......
declare var EASY_ENV_IS_NODE: boolean; declare var EASY_ENV_IS_NODE: boolean;
declare var EASY_ENV_IS_BROWSER: boolean; declare var EASY_ENV_IS_BROWSER: boolean;
type PlainObject<T = any> = { [key: string]: T }; type PlainObject<T = any> = { [key: string]: T };
\ No newline at end of file interface Window {
__INITIAL_STATE__: string | any;
}
declare var apollo: any;
...@@ -103,6 +103,11 @@ export default class Activity extends Mixins(TransformStyleMixin, SaMixin) { ...@@ -103,6 +103,11 @@ export default class Activity extends Mixins(TransformStyleMixin, SaMixin) {
const transformY = transform.split('(')[1].split(')')[0].split(',')[5]; const transformY = transform.split('(')[1].split(')')[0].split(',')[5];
gridItemEle.style.top = `${transformY}px`; gridItemEle.style.top = `${transformY}px`;
gridItemEle.className += ' del_transform'; gridItemEle.className += ' del_transform';
if (transform && transform.length) {
const transformY = transform.split('(')[1].split(')')[0].split(',')[5];
gridItemEle.style.top = `${transformY}px`;
gridItemEle.className += ' del_transform';
}
// 处理backgroundColor // 处理backgroundColor
const activityEle = document.querySelector('.activity'); const activityEle = document.querySelector('.activity');
const activityBgColor = getStyle(activityEle, 'backgroundColor'); const activityBgColor = getStyle(activityEle, 'backgroundColor');
......
...@@ -21,7 +21,10 @@ export default class EditorModule implements Module<EditorState, RootState> { ...@@ -21,7 +21,10 @@ export default class EditorModule implements Module<EditorState, RootState> {
actions: ActionTree<EditorState, RootState> = { actions: ActionTree<EditorState, RootState> = {
async getPageDate({ commit }, condition) { async getPageDate({ commit }, condition) {
const [res] = await api.getPageById(condition); const [res] = await api.getPageById(condition);
const { page, ...rest } = res as PageInfo; let { page, ...rest } = res as PageInfo;
if (!page) {
page = '[]';
}
commit(SET_PAGE_INFO, { ...rest, page: JSON.parse(page as string) }); commit(SET_PAGE_INFO, { ...rest, page: JSON.parse(page as string) });
} }
}; };
...@@ -31,8 +34,8 @@ export default class EditorModule implements Module<EditorState, RootState> { ...@@ -31,8 +34,8 @@ export default class EditorModule implements Module<EditorState, RootState> {
state.pageInfo = data; state.pageInfo = data;
}, },
[UPDATE_PAGE_INFO](state, { containerIndex, childIndex, data }) { [UPDATE_PAGE_INFO](state, { containerIndex, childIndex, data }) {
const page = (state.pageInfo.page as Page).elements; const page = (state.pageInfo.page as Page).elements || [];
if (childIndex || childIndex === 0) { if ((childIndex || childIndex === 0) && page[containerIndex].child) {
page[containerIndex].child.splice(childIndex, 1, data); page[containerIndex].child.splice(childIndex, 1, data);
} else { } else {
page.splice(containerIndex, 1, data); page.splice(containerIndex, 1, data);
......
#!/usr/bin/env node
"use strict";
const path = require('path');
const fs = require('fs');
const apollo = require('@qg/apollo-nodejs');
const npm = require("npm");
npm.load(() => {
apollo.load({
appId: 'quantum-block-h5',
configPath: path.resolve(__dirname, '../config'),
}).then(() => {
const { api, qiniu } = require(path.resolve('./config/apollo.json'));
fs.writeFileSync(path.resolve('./config/apollo.ssr.json'), JSON.stringify({ ...api, ...qiniu }));
});
});
\ No newline at end of file
#!/usr/bin/env node #!/usr/bin/env node
"use strict"; "use strict";
const path = require('path');
const fs = require('fs');
const apollo = require('@qg/apollo-nodejs');
const npm = require("npm"); const npm = require("npm");
npm.load(() => { npm.load(() => {
if (process.env.NODE_ENV === 'production') { apollo.load({
npm.run("start"); appId: 'quantum-block-h5',
} else { configPath: path.resolve(__dirname, '../config'),
npm.run("test"); }).then(() => {
} const { api, qiniu } = require(path.resolve('./config/apollo.json'));
fs.writeFileSync(path.resolve('./config/apollo.ssr.json'), JSON.stringify({ ...api, ...qiniu }));
if (process.env.NODE_ENV === 'production') {
npm.run("start");
} else {
npm.run("test");
}
});
}); });
\ No newline at end of file
...@@ -13,25 +13,14 @@ export default (appInfo: EggAppConfig) => { ...@@ -13,25 +13,14 @@ export default (appInfo: EggAppConfig) => {
dir: '/home/quant_group/logs', dir: '/home/quant_group/logs',
}; };
const prodRedisConfig = { exports.redis = {
client: { client: {
port: 6379, // Redis port port: 6379, // Redis port
host: 'front-redis.quantgroups.com', // Redis host host: 'front-redis.quantgroups.com', // Redis host
password: 'ln4^ESq80j4nrTMZ', password: 'ln4^ESq80j4nrTMZ',
db: 0 db: 0
} }
}; };;
const localRedisConfig = {
client: {
port: 31565, // Redis port
host: '172.17.5.13', // Redis host
password: '',
db: 0
}
};
exports.redis = process.env.NAMESPACE ? localRedisConfig : prodRedisConfig;
return exports; return exports;
}; };
import { Application, EggAppConfig } from 'egg'; import { Application, EggAppConfig } from 'egg';
const path = require('path');
const { redis, api, qiniu } = require(path.resolve(__dirname, './apollo.json'));
export default (appInfo: EggAppConfig) => { export default (appInfo: EggAppConfig) => {
const exports: any = {}; const exports: any = {};
exports.logger = {
dir: '/home/quant_group/logs',
};
exports.redis = {
client: redis
};
return exports; return {...exports, apollo: { ...api, ...qiniu }};
}; };
declare module "*.json" {
const value: any;
export default value;
}
\ No newline at end of file
...@@ -3,12 +3,13 @@ ...@@ -3,12 +3,13 @@
"version": "0.0.1", "version": "0.0.1",
"description": "低代码平台", "description": "低代码平台",
"scripts": { "scripts": {
"start": "egg-scripts start --port 9050", "start": "cross-env NODE_ENV=production APOLLO_CLUSTER=3C egg-scripts start --port 9050",
"test": "egg-scripts start --port 80 --workers 1", "test": "cross-env NODE_ENV=production EGG_SERVER_ENV=sit DEBUG=apollo APOLLO_CLUSTER=k8s NAMESPACE=qa2 egg-scripts start --port 80 --workers 1",
"stop": "egg-scripts stop", "stop": "egg-scripts stop",
"backend": "nohup egg-scripts start --port 7001 --workers 4", "backend": "nohup egg-scripts start --port 7001 --workers 4",
"dev": "egg-bin dev -r egg-ts-helper/register", "dev": "egg-bin dev -r egg-ts-helper/register",
"debug": "egg-bin debug -r egg-ts-helper/register", "debug": "egg-bin debug -r egg-ts-helper/register",
"apollo": "node bin/apollo.js",
"build": "cross-env COS_ENV=production easy build --devtool", "build": "cross-env COS_ENV=production easy build --devtool",
"build:test": "cross-env COS_ENV=test easy build --devtool", "build:test": "cross-env COS_ENV=test easy build --devtool",
"tsc": "ets && tsc -p tsconfig.json", "tsc": "ets && tsc -p tsconfig.json",
...@@ -62,7 +63,7 @@ ...@@ -62,7 +63,7 @@
"tslint-eslint-rules": "^5.4.0", "tslint-eslint-rules": "^5.4.0",
"tslint-loader": "^3.5.3", "tslint-loader": "^3.5.3",
"typescript": "^3.9.2", "typescript": "^3.9.2",
"webpack-sentry-plugin": "^1.16.0" "webpack-sentry-plugin": "^2.0.3"
}, },
"egg": { "egg": {
"typescript": true "typescript": true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment