第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

openshift 使用nodejs部署 vue項(xiàng)目

標(biāo)簽:
Docker

由于在服务器上打包发布vue项目很慢,也很消耗服务器资源,所有把这个过程放到本地来进行,本地打包好项目后提交到git. openshift build  下载源代码后直接使用打包好的文件 启动 express服务器

1. 覆盖openshift 已经有的s2i 中nodejs 的脚本代码

在根目录下面创建文件夹 .s2i\bin ,在 .s2i\bin 创建两个文件 assemble run
assemble文件内容:
#!/bin/bash

# Prevent running assemble in builders different than official STI image.# The official nodejs:6-onbuild already run npm install and use different# application folder.[ -d "/usr/src/app" ] && exit 0set -e# FIXME: Linking of global modules is disabled for now as it causes npm failures#        under RHEL7# Global modules good to have# npmgl=$(grep "^\s*[^#\s]" ../etc/npm_global_module_list | sort -u)# Available global modules; only match top-level npm packages#global_modules=$(npm ls -g 2> /dev/null | perl -ne 'print "$1\n" if /^\S+\s(\S+)\@[\d\.-]+/' | sort -u)# List all modules in common#module_list=$(/usr/bin/comm -12 <(echo "${global_modules}") | tr '\n' ' ')# Link the modules#npm link $module_listsafeLogging () {    if [[ $1 =~ http[s]?://.*@.*$ ]]; then
        echo $1 | sed 's/^.*@/redacted@/'
    else
        echo $1
    fi}shopt -s dotglobecho "---> Installing application source ..."mv /tmp/src/* ./if [ ! -z $HTTP_PROXY ]; then
    echo "---> Setting npm http proxy to" $(safeLogging $HTTP_PROXY)
    npm config set proxy $HTTP_PROXYfiif [ ! -z $http_proxy ]; then
    echo "---> Setting npm http proxy to" $(safeLogging $http_proxy)
    npm config set proxy $http_proxyfiif [ ! -z $HTTPS_PROXY ]; then
    echo "---> Setting npm https proxy to" $(safeLogging $HTTPS_PROXY)
    npm config set https-proxy $HTTPS_PROXYfiif [ ! -z $https_proxy ]; then
    echo "---> Setting npm https proxy to" $(safeLogging $https_proxy)
    npm config set https-proxy $https_proxyfi# Change the npm registry mirror if providedif [ -n "$NPM_MIRROR" ]; then
    npm config set registry $NPM_MIRRORfiecho "---> Building your Node application from source"npm install express http-proxy-middleware ejs# Fix source directory permissionsfix-permissions ./

run  文件内容
#!/bin/bash

# S2I run script for the 'nodejs' image.# The run script executes the server that runs your application.## For more information see the documentation:#   https://github.com/openshift/source-to-image/blob/master/docs/builder_image.md#set -eif [ -e "/opt/app-root/etc/generate_container_user" ]; then
  source /opt/app-root/etc/generate_container_userfi# Runs the nodejs application server. If the container is run in development mode,# hot deploy and debugging are enabled.run_node() {  echo -e "Environment: \n\tDEV_MODE=${DEV_MODE}\n\tNODE_ENV=${NODE_ENV}\n\tDEBUG_PORT=${DEBUG_PORT}"
  if [ "$DEV_MODE" == true ]; then
    echo "Launching via nodemon..."
    exec nodemon --debug="$DEBUG_PORT"
  else
    echo "Launching via npm..."
    exec npm run -d $NPM_RUN
  fi}#Set the debug port to 5858 by default.if [ -z "$DEBUG_PORT" ]; then
  export DEBUG_PORT=5858fi# Set the environment to development by default.if [ -z "$DEV_MODE" ]; then
  export DEV_MODE=falsefi# If NODE_ENV is not set by the user, then NODE_ENV is determined by whether# the container is run in development mode.if [ -z "$NODE_ENV" ]; then
  if [ "$DEV_MODE" == true ]; then
    export NODE_ENV=development  else
    export NODE_ENV=production  fifi# If the official dockerhub node image is used, skip the SCL setup below# and just run the nodejs serverif [ -d "/usr/src/app" ]; then
  run_nodefi# Allow users to inspect/debug the builder image itself, by using:# $ docker run -i -t openshift/centos-nodejs-builder --debug#[ "$1" == "--debug" ] && exec /bin/bash

run_node

2. 配置vue 项目服务器接口代理

module.exports = {
  dev: {    // Paths
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {      '/server': {
        target: 'http://health-server.shiwaixiangcun.cn',
        changeOrigin: true
      }
    },
  }
.....
}

3. 配置启动express服务器的文件

在根路径下面创建server.js文件
var express = require('express');
var app = express();
var proxyMiddleware = require('http-proxy-middleware')
var config = require('./config')
var proxyTable = config.dev.proxyTable

app.set('port', (process.env.PORT || 8080));           //设置端口app.use(express.static(__dirname + '/dist',{maxAge: 24*60*60*1000}));         //设置静态文件目录// views is directory for all template filesapp.set('views', __dirname + '/dist');                 //设置页面文件目录app.set('view engine', 'ejs');                          //设置模板引擎为ejsapp.get('/', function (request, response) {
  response.render('index');
});// proxy api requestsObject.keys(proxyTable).forEach(function (context) {  var options = proxyTable[context]  if (typeof options === 'string') {
    options = {target: options}
  }
  app.use(proxyMiddleware(options.filter || context, options))
});

app.get('*', function (request, response) {  //404
  response.render('index');
});

app.listen(app.get('port'), function () {             //启动服务器,监听上面设置的端口
  console.log('Node app is running on port', app.get('port'));
});

4. package.json 添加script

"scripts": {    "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",    "start": "node server.js",    "build": "cnpm install && node build/build.js"
  }



作者:9527华安
链接:https://www.jianshu.com/p/27634d77b941


點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺(jué)得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫(xiě)下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開(kāi)微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專(zhuān)欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消