在将hapijs部署到谷歌应用引擎时出现502网关错误

时间:2017-12-04 18:39:27

标签: node.js google-app-engine hapijs

日志告诉我没有提供图标

"GET /favicon.ico" 502

的app.yaml

runtime: nodejs
env: flex

server.js

const Hapi = require('hapi');
const Vision = require('vision');
const Inert = require('inert');
const Path = require('path');
const Handlebars = require('handlebars');

async function start() {
  const server = new Hapi.Server({ host: 'localhost', port: process.env.PORT || 8080 });

  await server.register([Inert, Vision]);

  server.views({ engines: { html: Handlebars }, path: `${__dirname}/templates` });

  const rootHandler = (request, h) => {
    return h.view('index', {
      title: "Data Controller",
      message: "All hail the DC Dashboard",
      meta: `Hapi ${request.server.version}`
    });
  };

  server.route({ method: 'GET', path: '/', handler: rootHandler });
  server.route({ method: 'GET', path: '/{param*}', handler: { directory: { path: `${__dirname}/public` }}});
  server.route({ method: 'GET', path: '/favicon.ico', handler: { file: `${__dirname}/public/favicon.ico` }, config: { cache: { expiresIn: 86400000 }}});

  try {
    await server.start();
  }
  catch (err) {
    console.log(err);
    process.exit(1);
  }

  console.log('Server running at:', server.info.uri);
};

start();

文件夹结构:

/
- public
 - css
 - js
 favicon.ico
server.js

我只是不确定如何解决这个问题!任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:1)

好吧我通过将主机设置为

解决了这个问题
0.0.0.0