rockq-org / austack-core

API, Console, Test of austack
32 stars 8 forks source link

config api url for client in production and development #51

Closed hailiang-wang closed 9 years ago

hailiang-wang commented 9 years ago

Description

Solution

build

env=production gulp build

development

for default the gulp task will take it as development env

./gulp/config.js

module.exports = function (options) {
  gulp.task('config', function () {
    var env = options.env || 'development';
    gulp.src(options.src + '/app/config/env-' + env + '.json')
      .pipe($.ngConstant({
        name: 'austackApp.config',
        templatePath: options.src + '/app/config/config.tpl.ejs',
        deps: []
      }))
      .pipe($.rename(options.src + '/app/config.js'))
      .pipe(gulp.dest(''));
  });
};
hailiang-wang commented 9 years ago

Staging service

Client - http://austack-stg-client.arrking.com/ --> 七牛

Server

http://austack-stg-server.arrking.com --> 115.28.162.221

hailiang-wang commented 9 years ago

Build, Start services as production

Server

export NODE_ENV=production # or 
pm2 restart austack-server.js

image

image

Client

how to inject configurations dynamically for production and development ? Can we have some strategy as the server ?

image

hailiang-wang commented 9 years ago

@lymanlai @nihgwu Since gulp build is compress the client codes into dist, then dist is published into qiniu for testing. But dist is always compressed, it is not friendly for debugging with staging service. So we should create another issue to enable gulp build with non-compress, maybe gulp build:raw.

hailiang-wang commented 9 years ago

Basically, the client's configurations or constants should be injected in this way: (1) first, there should be two config file, something like development.json and production.json (2) then, use gulp serve, development.json is used as config or constants. (3) when use gulp build, production.json is used for config or constants.

hailiang-wang commented 9 years ago

@lymanlai @nihgwu All HTTP Request with $resource or $http should use api url in Config module. Even it is in development and use proxy. Since then, we can connect client and server for production usage.

lymanlai commented 9 years ago

production

http://www.austack.com/ for index page http://manager.austack.com/ for admin(dave) to use http://api.austack.com/ for api server

but we need http://preview.www.austack.com/ for our production online test, this will use nginx and host for the dist folder on our own sever, after we confirm everything is all right, then use the qiniu tool to sync online

lymanlai commented 9 years ago

actully, we do not need proxy in the gulp then. cause our production will be cross domain.

lymanlai commented 9 years ago

start server

cd ~/git/austack
NODE_ENV=production npm start
lymanlai commented 9 years ago

find this gulp plugin: https://www.npmjs.com/package/gulp-angular-constant/

hailiang-wang commented 9 years ago

Multiple Environments is what we need

image

hailiang-wang commented 9 years ago

@nihgwu I think we can use this gulp plugin for configuration for client instead of writing something alike.

lymanlai commented 9 years ago

build

env=production gulp build

development

for default the gulp task will take it as development env

./gulp/config.js

module.exports = function (options) {
  gulp.task('config', function () {
    var env = options.env || 'development';
    gulp.src(options.src + '/app/config/env-' + env + '.json')
      .pipe($.ngConstant({
        name: 'austackApp.config',
        templatePath: options.src + '/app/config/config.tpl.ejs',
        deps: []
      }))
      .pipe($.rename(options.src + '/app/config.js'))
      .pipe(gulp.dest(''));
  });
};