Commit 28b1e5d5 authored by 郭志伟's avatar 郭志伟

fix: apollo配置文件引入方式调整

parent 7f02c92a
...@@ -18,6 +18,7 @@ config/plugin.local.js ...@@ -18,6 +18,7 @@ config/plugin.local.js
config/plugin.js config/plugin.js
config/config.*.js config/config.*.js
config/apollo.json config/apollo.json
config/apollo.ssr.json
index.js index.js
config/manifest.json config/manifest.json
app/view/* app/view/*
......
...@@ -9,12 +9,12 @@ export default class EditorController extends Controller { ...@@ -9,12 +9,12 @@ export default class EditorController extends Controller {
} }
public async home(ctx: Context) { public async home(ctx: Context) {
let cfg = {}; let apollo = {};
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === 'production' && process.env.EGG_SERVER_ENV === 'sit') {
const { api, qiniu } = await import(path.resolve('./config/apollo.json')); apollo = ctx.app.config.apollo || {};
cfg = { apollo: {...api, ...qiniu} };
} }
await ctx.renderClient('editor.js', cfg);
await ctx.renderClient('editor.js', { apollo });
} }
public async save(ctx: Context) { public async save(ctx: Context) {
......
#!/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";
const path = require('path'); const path = require('path');
const fs = require('fs');
const apollo = require('@qg/apollo-nodejs'); const apollo = require('@qg/apollo-nodejs');
"use strict";
const npm = require("npm"); const npm = require("npm");
npm.load(() => { npm.load(() => {
apollo.load({ apollo.load({
appId: 'quantum-blocks', appId: 'quantum-block-h5',
configPath: path.resolve(__dirname, '../config'), configPath: path.resolve(__dirname, '../config'),
}).then(() => { }).then(() => {
console.log(">>> apollo file", require(path.resolve('./config/apollo.json'))); 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') { 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 });
\ No newline at end of file
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
const path = require('path'); const path = require('path');
import { Application, EggAppConfig } from 'egg'; import { Application, EggAppConfig } from 'egg';
const { mysql, redis, api, qiniu } = require(path.resolve('./config/apollo.json'));
export default (appInfo: EggAppConfig) => { export default (appInfo: EggAppConfig) => {
const { mysql, redis } = require(path.resolve('./config/apollo.json'));
const exports: any = {}; const exports: any = {};
exports.logger = { exports.logger = {
dir: '/home/quant_group/logs', dir: '/home/quant_group/logs',
...@@ -20,5 +20,5 @@ export default (appInfo: EggAppConfig) => { ...@@ -20,5 +20,5 @@ export default (appInfo: EggAppConfig) => {
}, },
client: redis client: redis
}; };
return exports; return {...exports, apollo: { ...api, ...qiniu }};
}; };
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
"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": "easy build --devtool", "build": "easy build --devtool",
"tsc": "ets && tsc -p tsconfig.json", "tsc": "ets && tsc -p tsconfig.json",
"clean": "ets clean", "clean": "ets clean",
......
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