将基于灵活工具链的ReactJs应用程序部署到Gcloud

时间:2018-09-01 13:19:14

标签: node.js reactjs webpack gcloud yarnpkg

我使用以下工具链创建了一个多页面的ReactJs应用程序:

  • 纱线(包装管理器)
  • Webpack(捆绑软件)
  • Babel(编译器)

部署到Gcloud后,只有登录页面有效。每隔一页显示此错误:

  

未找到

我的 app.yaml 看起来像这样

runtime: nodejs
env: flex

handlers:
  - url: /
    static_files: dist/index.html
    upload: dist/index.html

  - url: /(.*)
    static_files: dist/index.html
    upload: dist/index.html
package.json

中的

脚本

"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1",
  "start": "NODE_ENV=production webpack --progress && NODE_ENV=production node server.js",
  "dev": "webpack-dev-server --mode development",
  "build": "webpack --mode production"
}

server.js 看起来像这样

'use strict';

const port = process.env.PORT || 3000;
const Koa = require('koa');
const serve = require('koa-static');
const convert = require('koa-convert');
const app = new Koa();
const _use = app.use;
app.use = (x) => _use.call(app, convert(x));
app.use(serve('./dist'));

const server = app.listen(port, function () {
 let host = server.address().address;
 let port = server.address().port;
 console.log('listening at http://%s:%s', host, port);
});

app.js 与路由器

render() {
  return (
    <Router history={browserHistory}>
      <Switch>
        <Route exact path="/" component={LandingPage} />
        <Route path="/about" component={AboutUsPage} />
      </Switch>
    </Router>
  );
}

我尝试更改app.yaml中的处理程序,也尝试更改server.js,但没有任何效果。任何帮助将不胜感激。

注意:应用程序可以在我的本地环境中完美运行。

0 个答案:

没有答案
相关问题