2019.06.19 11:21

Next.js 使用指南--部署篇pm2

Next.js 使用指南--部署篇pm2

next

这样的配置默认 3000端口

<span class="hljs-string">"scripts"</span>: {
   <span class="hljs-string">"dev"</span>: <span class="hljs-string">"next"</span>,
   <span class="hljs-string">"build"</span>: <span class="hljs-string">"next build"</span>,
   <span class="hljs-string">"start"</span>: <span class="hljs-string">"next start"</span>
 },

报错

pm2 next start (function (exports, require, module, __filename, __dirname) { :: Created by npm, please don't edit manually.
cmd bug windos

用server.js解决 windows pm2 的bug

<span class="hljs-number">551</span>  npm start
  <span class="hljs-number">552</span>  pm2 start npm --name <span class="hljs-string">"my-next"</span> -- run build
  <span class="hljs-number">553</span>  pm2 ls
  <span class="hljs-number">554</span>  pm2 logs
  <span class="hljs-number">555</span>  pm2 ls
  <span class="hljs-number">556</span>   pm2 start npm --name <span class="hljs-string">"my-nuxt"</span> -- run start

errored 因为 windows pm2 的bug

用下面这个可以运行 完美

<span class="hljs-comment">//server.js</span>
<span class="hljs-comment">// var cmd=require('node-cmd');</span>
<span class="hljs-comment">// cmd.run('npm start');</span>

<span class="hljs-comment">//or </span>
var exec = require(<span class="hljs-string">'child_process'</span>).exec;
exec(<span class="hljs-string">'npm run start'</span>, {windowsHide: <span class="hljs-literal">true</span>});
<span class="hljs-symbol">lenovo@</span>lenovo-PC MINGW64 /e/jackieli/react-day-to-day/next
$ pm2 start server.js --name next -i <span class="hljs-number">3</span>
[PM2] Starting E:\jackieli\react-day-to-day\next\server.js <span class="hljs-keyword">in</span> cluster_mode (<span class="hljs-number">3</span> instances)
[PM2] Done.
┌──────────┬────┬─────────┬─────────┬───────┬─────────┬─────────┬────────┬─────┬───────────┬────────┬──────────┐
│ App name │ id │ version │ mode    │ pid   │ status  │ restart │ uptime │ cpu │ mem       │ user   │ watching │
├──────────┼────┼─────────┼─────────┼───────┼─────────┼─────────┼────────┼─────┼───────────┼────────┼──────────┤
│ my-next  │ <span class="hljs-number">0</span>  │ N/A     │ fork    │ <span class="hljs-number">0</span>     │ errored │ <span class="hljs-number">15</span>      │ <span class="hljs-number">0</span>      │ <span class="hljs-number">0</span>%  │ <span class="hljs-number">0</span> B       │ lenovo │ disabled │
│ my-nuxt  │ <span class="hljs-number">1</span>  │ N/A     │ fork    │ <span class="hljs-number">0</span>     │ errored │ <span class="hljs-number">15</span>      │ <span class="hljs-number">0</span>      │ <span class="hljs-number">0</span>%  │ <span class="hljs-number">0</span> B       │ lenovo │ disabled │
│ next     │ <span class="hljs-number">2</span>  │ <span class="hljs-number">1.0.0</span>   │ cluster │ <span class="hljs-number">17536</span> │ online  │ <span class="hljs-number">0</span>       │ <span class="hljs-number">2</span>s     │ <span class="hljs-number">0</span>%  │ <span class="hljs-number">30.8</span> MB   │ lenovo │ disabled │
│ next     │ <span class="hljs-number">3</span>  │ <span class="hljs-number">1.0.0</span>   │ cluster │ <span class="hljs-number">18016</span> │ online  │ <span class="hljs-number">0</span>       │ <span class="hljs-number">1</span>s     │ <span class="hljs-number">0</span>%  │ <span class="hljs-number">30.7</span> MB   │ lenovo │ disabled │
│ next     │ <span class="hljs-number">4</span>  │ <span class="hljs-number">1.0.0</span>   │ cluster │ <span class="hljs-number">18496</span> │ online  │ <span class="hljs-number">0</span>       │ <span class="hljs-number">1</span>s     │ <span class="hljs-number">0</span>%  │ <span class="hljs-number">30.4</span> MB   │ lenovo │ disabled │
└──────────┴────┴─────────┴─────────┴───────┴─────────┴─────────┴────────┴─────┴───────────┴────────┴──────────┘
 Use `pm2 show <id|name>` to <span class="hljs-keyword">get</span> more details about an app

改变端口

<span class="hljs-string">"scripts"</span>: {
    <span class="hljs-string">"dev"</span>: <span class="hljs-string">"next -p 8088"</span>,
    <span class="hljs-string">"start"</span>: <span class="hljs-string">"next start -p 3033"</span>,
    <span class="hljs-string">"build"</span>: <span class="hljs-string">"next build"</span>
  }
lenovo<span class="hljs-symbol">@lenovo</span>-PC MINGW64 /e/jackieli/react-day-<span class="hljs-keyword">to</span>-day/<span class="hljs-keyword">next</span>
$ npm <span class="hljs-built_in">run</span> dev

> <span class="hljs-keyword">next</span><span class="hljs-symbol">@1</span><span class="hljs-number">.0.0</span> dev E:\jackieli\react-day-<span class="hljs-keyword">to</span>-day\<span class="hljs-keyword">next</span>
> <span class="hljs-keyword">next</span> -p <span class="hljs-number">8088</span>

[ wait ]  starting the development server ...
[ info ]  waiting on http://localhost:<span class="hljs-number">8088</span> ...

lenovo<span class="hljs-symbol">@lenovo</span>-PC MINGW64 /e/jackieli/react-day-<span class="hljs-keyword">to</span>-day/<span class="hljs-keyword">next</span>
$ npm start

> <span class="hljs-keyword">next</span><span class="hljs-symbol">@1</span><span class="hljs-number">.0.0</span> start E:\jackieli\react-day-<span class="hljs-keyword">to</span>-day\<span class="hljs-keyword">next</span>
> <span class="hljs-keyword">next</span> start -p <span class="hljs-number">3033</span>

> Ready on http://localhost:<span class="hljs-number">3033</span>


set PORT=<span class="hljs-number">3001</span>
Windows 系统在 cmd.exe 中运行 $ set PORT=<span class="hljs-number">1000</span>

macOS &amp; Linux 运行 $ PORT=<span class="hljs-number">1000</span>

再运行 $ npm start 启动 RSSHub 即可将监听端口设置为 <span class="hljs-number">1000.</span>

报错 没有a标签

function About() {
  return <span class="hljs-tag"><<span class="hljs-name">div</span>></span>about! <span class="hljs-tag"><<span class="hljs-name">br</span>/><<span class="hljs-name">Link</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"/"</span>></span>
      go home
    <span class="hljs-tag"></<span class="hljs-name">Link</span>></<span class="hljs-name">div</span>></span>;
}
utils.js:9 Warning: You're using a string directly inside <span class="hljs-tag"><<span class="hljs-name">Link</span>></span>. This usage has been deprecated. Please add an <span class="hljs-tag"><<span class="hljs-name">a</span>></span> tag as child of <span class="hljs-tag"><<span class="hljs-name">Link</span>></span>

要这样 用 
function About() {
  return <span class="hljs-tag"><<span class="hljs-name">div</span>></span>about! <span class="hljs-tag"><<span class="hljs-name">br</span>/><<span class="hljs-name">Link</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"/"</span>><<span class="hljs-name">a</span>></span>go home<span class="hljs-tag"></<span class="hljs-name">a</span>></<span class="hljs-name">Link</span>></<span class="hljs-name">div</span>></span>;
}

静态化

输入下面命令:

next build
next export
你可以在package.json添加一个 NPM 脚本,如下所示:

{
  <span class="hljs-string">"scripts"</span>: {
    <span class="hljs-string">"build"</span>: <span class="hljs-string">"next build"</span>,
    <span class="hljs-string">"export"</span>: <span class="hljs-string">"npm run build &amp;&amp; next export"</span>
  }
}
接着只用执行一次下面命令:

npm run export
然后你将会有一个静态页面应用在out 目录下。
 <span class="hljs-string">"export"</span>: <span class="hljs-string">"npm run build &amp;&amp; next export"</span>

serve静态服务器

lenovo@lenovo-PC MINGW64 /e/jackieli/react-day-to-day/next
$ serve out
<span class="hljs-keyword">UPDATE</span> AVAILABLE The latest <span class="hljs-keyword">version</span> <span class="hljs-keyword">of</span> <span class="hljs-string">`serve`</span> <span class="hljs-keyword">is</span> <span class="hljs-number">11.0.1</span>
INFO: Accepting connections <span class="hljs-keyword">at</span> <span class="hljs-keyword">http</span>://localhost:<span class="hljs-number">5000</span>


lenovo@lenovo-PC MINGW64 /e/jackieli/react-<span class="hljs-keyword">day</span>-<span class="hljs-keyword">to</span>-<span class="hljs-keyword">day</span>/<span class="hljs-keyword">next</span>

express koa 部署

lenovo@lenovo-PC MINGW64 /e/jackieli/react-day-to-day/next

$ NODE_ENV=production PORT=3034 node koa-server.js

Ready on http://localhost:3034

###报错 nodemon server.js

lenovo@lenovo-PC MINGW64 /<span class="hljs-keyword">e</span>/jackieli/react-day-<span class="hljs-keyword">to</span>-day/<span class="hljs-keyword">next</span>
$ yarn <span class="hljs-built_in">add</span> koa koa-router --save
yarn <span class="hljs-built_in">add</span> v1.<span class="hljs-number">10.1</span>
error An unexpected error occurred: <span class="hljs-string">"E:\\jackieli\\react-day-to-day\\next\\package.json: Unexpected token } in JSON at position 433"</span>.
info If you think this <span class="hljs-keyword">is</span> <span class="hljs-keyword">a</span> bug, please <span class="hljs-keyword">open</span> <span class="hljs-keyword">a</span> bug report with the information provided in <span class="hljs-string">"E:\\jackieli\\react-day-to-day\\next\\yarn-error.log"</span>.
info Visit http<span class="hljs-variable">s:</span>//yarnpkg.<span class="hljs-keyword">com</span>/<span class="hljs-keyword">en</span>/docs/cli/<span class="hljs-built_in">add</span> <span class="hljs-keyword">for</span> documentation about this <span class="hljs-keyword">command</span>.

package.json 多了个 逗号 

lenovo@lenovo-PC MINGW64 /<span class="hljs-keyword">e</span>/jackieli/react-day-<span class="hljs-keyword">to</span>-day/<span class="hljs-keyword">next</span>
$ nodemon server.js
[nodemon] <span class="hljs-number">1.18</span>.<span class="hljs-number">6</span>
[nodemon] <span class="hljs-keyword">to</span> restart at any time, enter `rs`
[nodemon] watchin<span class="hljs-variable">g:</span> *.*
[nodemon] starting `node server.js`
[nodemon] restarting due <span class="hljs-keyword">to</span> <span class="hljs-keyword">changes</span>...
[nodemon] restarting due <span class="hljs-keyword">to</span> <span class="hljs-keyword">changes</span>...
[nodemon] starting `node server.js`
没了用

koa-server.js

<span class="hljs-regexp">//</span>http版本

<span class="hljs-regexp">//</span> const { createServer } = require(<span class="hljs-string">'http'</span>);
<span class="hljs-regexp">//</span> const <span class="hljs-keyword">next</span> = require(<span class="hljs-string">'next'</span>);
<span class="hljs-regexp">//</span> const port = parseInt(process.env.PORT, <span class="hljs-number">10</span>) || <span class="hljs-number">3000</span>;
<span class="hljs-regexp">//</span> const dev = process.env.NODE_ENV !== <span class="hljs-string">'production'</span>;
<span class="hljs-regexp">//</span> const app = <span class="hljs-keyword">next</span>({ dev });
<span class="hljs-regexp">//</span> const handler = app.getRequestHandler(app);
<span class="hljs-regexp">//</span> app.prepare()
<span class="hljs-regexp">//</span>   .then(() => {
<span class="hljs-regexp">//</span>     createServer(handler)
<span class="hljs-regexp">//</span>       .listen(port, (err) => {
<span class="hljs-regexp">//</span>         <span class="hljs-keyword">if</span> (err) throw err;
<span class="hljs-regexp">//</span>         console.log(`> Ready on http:<span class="hljs-regexp">//</span>localhost:<span class="hljs-variable">${port}</span>`);
<span class="hljs-regexp">//</span>       })
<span class="hljs-regexp">//</span>   })



<span class="hljs-regexp">//</span>koa版本


const Koa = require(<span class="hljs-string">'koa'</span>)
const <span class="hljs-keyword">next</span> = require(<span class="hljs-string">'next'</span>)
const Router = require(<span class="hljs-string">'koa-router'</span>)

const port = parseInt(process.env.PORT, <span class="hljs-number">10</span>) || <span class="hljs-number">3000</span>
const dev = process.env.NODE_ENV !== <span class="hljs-string">'production'</span>
const app = <span class="hljs-keyword">next</span>({ dev })
const handle = app.getRequestHandler()

app.prepare().then(() => {
    const server = new Koa()
    const router = new Router()

    <span class="hljs-regexp">//</span> router.get(<span class="hljs-string">'/a'</span>, async ctx => {
    <span class="hljs-regexp">//</span>   await app.render(ctx.req, ctx.res, <span class="hljs-string">'/b'</span>, ctx.query)
    <span class="hljs-regexp">//</span>   ctx.respond = false
    <span class="hljs-regexp">//</span> })

    <span class="hljs-regexp">//</span> router.get(<span class="hljs-string">'/b'</span>, async ctx => {
    <span class="hljs-regexp">//</span>   await app.render(ctx.req, ctx.res, <span class="hljs-string">'/a'</span>, ctx.query)
    <span class="hljs-regexp">//</span>   ctx.respond = false
    <span class="hljs-regexp">//</span> })

    router.get(<span class="hljs-string">'*'</span>, async ctx => {
      await handle(ctx.req, ctx.res)
      ctx.respond = false
    })

    server.use(async (ctx, <span class="hljs-keyword">next</span>) => {
      ctx.res.statusCode = <span class="hljs-number">200</span>
      await <span class="hljs-keyword">next</span>()
    })

    server.use(router.routes())
    server.listen(port, () => {
      console.log(`> Ready on http:<span class="hljs-regexp">//</span>localhost:<span class="hljs-variable">${port}</span>`)
    })
  }
)




<span class="hljs-regexp">//</span>express 版本
<span class="hljs-regexp">//</span> const express = require(<span class="hljs-string">'express'</span>)
<span class="hljs-regexp">//</span> const <span class="hljs-keyword">next</span> = require(<span class="hljs-string">'next'</span>)
<span class="hljs-regexp">//</span> <span class="hljs-regexp">//</span> const bodyParser = require(<span class="hljs-string">'body-parser'</span>)
<span class="hljs-regexp">//</span> <span class="hljs-regexp">//</span> const compression = require(<span class="hljs-string">'compression'</span>)
<span class="hljs-regexp">//</span> const { join } = require(<span class="hljs-string">'path'</span>)
<span class="hljs-regexp">//</span> const { parse } = require(<span class="hljs-string">'url'</span>)

<span class="hljs-regexp">//</span> const dev = process.env.NODE_ENV !== <span class="hljs-string">'production'</span>
<span class="hljs-regexp">//</span> const port = process.env.PORT || <span class="hljs-number">3000</span>
<span class="hljs-regexp">//</span> const app = <span class="hljs-keyword">next</span>({ dev })
<span class="hljs-regexp">//</span> const handle = app.getRequestHandler()

<span class="hljs-regexp">//</span> <span class="hljs-regexp">//</span> const Redis = require(<span class="hljs-string">'./services/redis'</span>)
<span class="hljs-regexp">//</span> <span class="hljs-regexp">//</span> const Auth = require(<span class="hljs-string">'./services/auth'</span>)
<span class="hljs-regexp">//</span> <span class="hljs-regexp">//</span> const Routes = require(<span class="hljs-string">'./services/routes'</span>)
<span class="hljs-regexp">//</span> app.prepare().then(() => {
<span class="hljs-regexp">//</span>   const server = express()

<span class="hljs-regexp">//</span>   <span class="hljs-regexp">//</span> server.use(bodyParser.json())
<span class="hljs-regexp">//</span>   <span class="hljs-regexp">//</span> server.use(bodyParser.urlencoded({ extended: false }))
<span class="hljs-regexp">//</span>   <span class="hljs-regexp">//</span> server.use(compression())

<span class="hljs-regexp">//</span>   <span class="hljs-regexp">//</span> Redis(server)
<span class="hljs-regexp">//</span>   <span class="hljs-regexp">//</span> Auth(server)
<span class="hljs-regexp">//</span>   <span class="hljs-regexp">//</span> Routes(server, app)

<span class="hljs-regexp">//</span>   server.get(<span class="hljs-string">'*'</span>, (req, res) => {
<span class="hljs-regexp">//</span>     const parsedUrl = parse(req.url, true)
<span class="hljs-regexp">//</span>     const { pathname } = parsedUrl

<span class="hljs-regexp">//</span>     <span class="hljs-keyword">if</span> (pathname === <span class="hljs-string">'/service-worker.js'</span>) {
<span class="hljs-regexp">//</span>       const filePath = join(__dirname, <span class="hljs-string">'.next'</span>, pathname)

<span class="hljs-regexp">//</span>       app.serveStatic(req, res, filePath)
<span class="hljs-regexp">//</span>     } <span class="hljs-keyword">else</span> {
<span class="hljs-regexp">//</span>       handle(req, res, parsedUrl)
<span class="hljs-regexp">//</span>     }
<span class="hljs-regexp">//</span>   })

<span class="hljs-regexp">//</span>   server.listen(port, err => {
<span class="hljs-regexp">//</span>     <span class="hljs-keyword">if</span> (err) throw err
<span class="hljs-regexp">//</span>     console.log(`> Ready on http:<span class="hljs-regexp">//</span>localhost:<span class="hljs-variable">${port}</span>`)
<span class="hljs-regexp">//</span>   })
<span class="hljs-regexp">//</span> })


改变端口 静态化


<span class="hljs-string">"scripts"</span>: {
  <span class="hljs-string">"dev1"</span>: <span class="hljs-string">"next"</span>,
  <span class="hljs-string">"build1"</span>: <span class="hljs-string">"next build"</span>,
  <span class="hljs-string">"start1"</span>: <span class="hljs-string">"next start"</span>,
  <span class="hljs-string">"dev"</span>: <span class="hljs-string">"next -p 8088"</span>,
  <span class="hljs-string">"start"</span>: <span class="hljs-string">"next start -p 3033"</span>,
  <span class="hljs-string">"build"</span>: <span class="hljs-string">"next build"</span>,
  <span class="hljs-string">"export"</span>: <span class="hljs-string">"next export"</span>,
  <span class="hljs-string">"static-run"</span>: <span class="hljs-string">"npm run build &amp;&amp; npm run export &amp;&amp; serve out"</span>,
  <span class="hljs-string">"start-local"</span>: <span class="hljs-string">"NODE_ENV=production PORT=3034 node koa-server.js"</span>
},


pm2 init ecosystem.config.js


module.exports = {
  apps : [
     {
      name: <span class="hljs-string">'api-mock-online-apis-environment-development'</span>,
      script: <span class="hljs-string">'server.js'</span>,
      instances: <span class="hljs-number">1</span>,
      autorestart: true,
      watch: true,
      max_memory_restart: <span class="hljs-string">'1G'</span>,
      restart_delay: <span class="hljs-number">3000</span>,
      append_env_to_name: true, <span class="hljs-regexp">//</span>这表示会把当前环境的名字跟在我们进程的名字后面,最后当我们使用 npm run prd 部署完生产服务后,会发现我们生产服务的名字为 mydemo-production,当我们使用 npm run test 部署完测试服务后,会发现我们测试服务的名字为 mydemo-test,这样就可以让一个项目的生产环境和测试环境同时运行在一个服务器上了。
      <span class="hljs-regexp">//</span> output: <span class="hljs-string">'./logs/out.log'</span>,
      <span class="hljs-regexp">//</span> error: <span class="hljs-string">'./logs/error.log'</span>,
      <span class="hljs-regexp">//</span> log: <span class="hljs-string">'./logs/combined.outerr.log'</span>,
      <span class="hljs-regexp">//</span> log_date_format: <span class="hljs-string">'YYYY-MM-DD HH:mm Z'</span>,

      env: {
        NODE_ENV: <span class="hljs-string">'development'</span>, <span class="hljs-regexp">//</span>dev
        PORT: <span class="hljs-number">3012</span>
      },
      env_test: {
        NODE_ENV: <span class="hljs-string">'test'</span>, <span class="hljs-regexp">//</span>test
        PORT: <span class="hljs-number">4012</span>
      },
      env_stage: {
        NODE_ENV: <span class="hljs-string">'stage'</span>, <span class="hljs-regexp">//</span>qa
        PORT: <span class="hljs-number">5012</span>
      },
      env_production: {
        NODE_ENV: <span class="hljs-string">'production'</span>, <span class="hljs-regexp">//</span>prod
        PORT: <span class="hljs-number">6012</span>
      }
    },
    <span class="hljs-regexp">//</span>开启下面注释的话 就是 注释掉上面的 append_env_to_name: true, 用reload 分别重启 或者script脚本

   <span class="hljs-regexp">//</span>pm2 reload ecosystem.config.js --env development === pm2 start ecosystem.config.js
   <span class="hljs-regexp">//</span> pm2 reload ecosystem.config.js --env test
   <span class="hljs-regexp">//</span> pm2 reload ecosystem.config.js --env stage
   <span class="hljs-regexp">//</span> pm2 reload ecosystem.config.js --env production

    <span class="hljs-regexp">//</span> {
    <span class="hljs-regexp">//</span>   name: <span class="hljs-string">'next'</span>,
    <span class="hljs-regexp">//</span>   script: <span class="hljs-string">'koa-server.js'</span>,
    <span class="hljs-regexp">//</span>   instances: <span class="hljs-number">1</span>,
    <span class="hljs-regexp">//</span>   autorestart: true,
    <span class="hljs-regexp">//</span>   watch: true,
    <span class="hljs-regexp">//</span>   max_memory_restart: <span class="hljs-string">'1G'</span>,
    <span class="hljs-regexp">//</span>   restart_delay: <span class="hljs-number">3000</span>,
    <span class="hljs-regexp">//</span>   env_test: {
    <span class="hljs-regexp">//</span>     NODE_ENV: <span class="hljs-string">'test'</span>, <span class="hljs-regexp">//</span>test
    <span class="hljs-regexp">//</span>     PORT: <span class="hljs-number">4012</span><span class="hljs-regexp">//</span>   }
    <span class="hljs-regexp">//</span> },
    <span class="hljs-regexp">//</span>    {
    <span class="hljs-regexp">//</span>   name: <span class="hljs-string">'api-mock-online-apis-environment-stage'</span>,
    <span class="hljs-regexp">//</span>   script: <span class="hljs-string">'server.js'</span>,
    <span class="hljs-regexp">//</span>   instances: <span class="hljs-number">1</span>,
    <span class="hljs-regexp">//</span>   autorestart: true,
    <span class="hljs-regexp">//</span>   watch: true,
    <span class="hljs-regexp">//</span>   max_memory_restart: <span class="hljs-string">'1G'</span>,
    <span class="hljs-regexp">//</span>   restart_delay: <span class="hljs-number">3000</span>,
    <span class="hljs-regexp">//</span>   env_stage: {
    <span class="hljs-regexp">//</span>     NODE_ENV: <span class="hljs-string">'stage'</span>, <span class="hljs-regexp">//</span>qa
    <span class="hljs-regexp">//</span>     PORT: <span class="hljs-number">5012</span><span class="hljs-regexp">//</span>   }
    <span class="hljs-regexp">//</span> },
    <span class="hljs-regexp">//</span>  {
    <span class="hljs-regexp">//</span>   name: <span class="hljs-string">'api-mock-online-apis-environment-production'</span>,
    <span class="hljs-regexp">//</span>   script: <span class="hljs-string">'server.js'</span>,
    <span class="hljs-regexp">//</span>   instances: <span class="hljs-number">1</span>,
    <span class="hljs-regexp">//</span>   autorestart: true,
    <span class="hljs-regexp">//</span>   watch: true,
    <span class="hljs-regexp">//</span>   max_memory_restart: <span class="hljs-string">'1G'</span>,
    <span class="hljs-regexp">//</span>   restart_delay: <span class="hljs-number">3000</span>,
    <span class="hljs-regexp">//</span>   <span class="hljs-regexp">//</span> env: {
    <span class="hljs-regexp">//</span>   <span class="hljs-regexp">//</span>   NODE_ENV: <span class="hljs-string">'development'</span>, <span class="hljs-regexp">//</span>dev
    <span class="hljs-regexp">//</span>   <span class="hljs-regexp">//</span>   PORT: <span class="hljs-number">3012</span><span class="hljs-regexp">//</span>   <span class="hljs-regexp">//</span> },
    <span class="hljs-regexp">//</span>   <span class="hljs-regexp">//</span> env_test: {
    <span class="hljs-regexp">//</span>   <span class="hljs-regexp">//</span>   NODE_ENV: <span class="hljs-string">'test'</span>, <span class="hljs-regexp">//</span>test
    <span class="hljs-regexp">//</span>   <span class="hljs-regexp">//</span>   PORT: <span class="hljs-number">4012</span><span class="hljs-regexp">//</span>   <span class="hljs-regexp">//</span> },
    <span class="hljs-regexp">//</span>   <span class="hljs-regexp">//</span> env_stage: {
    <span class="hljs-regexp">//</span>   <span class="hljs-regexp">//</span>   NODE_ENV: <span class="hljs-string">'stage'</span>, <span class="hljs-regexp">//</span>qa
    <span class="hljs-regexp">//</span>   <span class="hljs-regexp">//</span>   PORT: <span class="hljs-number">5012</span><span class="hljs-regexp">//</span>   <span class="hljs-regexp">//</span> },
    <span class="hljs-regexp">//</span>   env_production: {
    <span class="hljs-regexp">//</span>     NODE_ENV: <span class="hljs-string">'production'</span>, <span class="hljs-regexp">//</span>prod
    <span class="hljs-regexp">//</span>     PORT: <span class="hljs-number">6012</span><span class="hljs-regexp">//</span>   }
    <span class="hljs-regexp">//</span> },
  ],

  <span class="hljs-regexp">//</span> deploy : {
  <span class="hljs-regexp">//</span>   production : {
  <span class="hljs-regexp">//</span>     user : <span class="hljs-string">'node'</span>,
  <span class="hljs-regexp">//</span>     host : <span class="hljs-string">'212.83.163.1'</span>,
  <span class="hljs-regexp">//</span>     ref  : <span class="hljs-string">'origin/master'</span>,
  <span class="hljs-regexp">//</span>     repo : <span class="hljs-string">'git@github.com:repo.git'</span>,
  <span class="hljs-regexp">//</span>     path : <span class="hljs-string">'/var/www/production'</span>,
  <span class="hljs-regexp">//</span>     <span class="hljs-string">'post-deploy'</span> : <span class="hljs-string">'npm install &amp;&amp; pm2 reload ecosystem.config.js --env production'</span><span class="hljs-regexp">//</span>   }
  <span class="hljs-regexp">//</span> }
};

DIY表情

(添加http或https协议)

提交评论