Commit 2dab0b1d authored by 郭志伟's avatar 郭志伟

build: 添加apollo

parent a3a30c48
...@@ -17,6 +17,7 @@ app/**/*.js ...@@ -17,6 +17,7 @@ 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
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) {
const { api, qiniu } = await import(path.resolve('./config/apollo.json'));
const redisKey = `quantum-blocks:page:${ctx.params.id}`; const redisKey = `quantum-blocks:page:${ctx.params.id}`;
let body = await ctx.service.redis.get(redisKey); let body = await ctx.service.redis.get(redisKey);
if (body) { if (body) {
...@@ -12,6 +13,10 @@ export default class ActivityController extends Controller { ...@@ -12,6 +13,10 @@ export default class ActivityController extends Controller {
body = await ctx.renderView('activity.js', { url: ctx.url }); body = await ctx.renderView('activity.js', { url: ctx.url });
await ctx.service.redis.set(redisKey, body); await ctx.service.redis.set(redisKey, body);
} }
if (process.env.NODE_ENV === 'production') {
const firstScriptTagIndex = body.indexOf('<script');
body = `${body.slice(0, firstScriptTagIndex)}<script>var apollo = ${JSON.stringify({...api, ...qiniu} )};</script>${body.slice(firstScriptTagIndex, body.length - 1)}`;
}
ctx.body = body; ctx.body = body;
} }
} }
\ No newline at end of file
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
}; };
if (EASY_ENV_IS_BROWSER) {
const apolloCfg = window.apollo || window.__INITIAL_STATE__.apollo;
if (apolloCfg) {
for (const key in apolloCfg) {
if (apolloCfg[key]) {
hostMap[key] = apolloCfg[key];
}
}
}
}
export default hostMap;
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 apolloCfg = window.apollo || window.__INITIAL_STATE__.apollo;
if (apolloCfg) {
for (const key in apolloCfg) {
if (apolloCfg[key]) {
hostMap[key] = apolloCfg[key];
}
}
}
}
export default hostMap;
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 };
interface Window {
__INITIAL_STATE__: string | any;
}
declare var apollo: any;
#!/usr/bin/env node #!/usr/bin/env node
"use strict"; "use strict";
const path = require('path');
const apollo = require('@qg/apollo-nodejs');
const npm = require("npm"); const npm = require("npm");
npm.load(() => { npm.load(() => {
apollo.load({
appId: 'quantum-block-h5',
configPath: path.resolve(__dirname, '../config'),
}).then(() => {
console.log(">>> apollo file", require(path.resolve('./config/apollo.json')));
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === 'production') {
npm.run("start"); npm.run("start");
} else { } else {
npm.run("test"); 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');
export default (appInfo: EggAppConfig) => { export default (appInfo: EggAppConfig) => {
const exports: any = {}; const exports: any = {};
const { redis } = require(path.resolve('./config/apollo.json'));
exports.redis = {
default: {
keyPrefix: appInfo.name + ':',
},
client: redis
};
return exports; return exports;
}; };
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
"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",
......
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