I have a regular Node(v12) http server on App Engine. I switched to http2 with http2.createSecureServer
. It works in development, but deploying to App Engine and after the server starts successfully it responds to requests with 502 bad gateway...
I tried to switch to http2.createServer
to not use https, and the request never receives a response (forever loading). The last log in App Engine Log Explorer for that request shows:
[error] 27#27: *2 upstream sent no valid HTTP/1.0 header
while reading response header from upstream, client:
169.254.1.1, server: _, request: "GET / HTTP/1.1",
upstream: "http://127.0.0.1:8081/"
It seems like it somehow is expecting http1, but I don't know why. I also don't know why it's on port 8081, I have the port set to 8080.
After spending my day searching Google and their docs for anything on using http2 with App Engine, I'm burnt out. And, their support page says "post on Stack Overflow"..
main.js
const http2 = require('http2');
const fs = require('fs');
const app = new (require('koa'))();
const logger = require('koa-logger');
const bodyParser = require('koa-bodyparser');
const json = require('koa-json');
const cors = require('@koa/cors');
const router = require('./router.js');
const { PORT, HOST, KEY, CERT } = require('./config.js');
app.use(logger());
app.use(bodyParser());
app.use(json());
app.use(cors({ exposeHeaders: 'authorization' }));
app.use(router.routes());
app.use(router.allowedMethods());
const server = http2
.createSecureServer(
{
key: fs.readFileSync(KEY),
cert: fs.readFileSync(CERT),
allowHTTP1: true
},
app.callback()
)
.listen(PORT, () => {
console.log(`Koa HTTP/2 running at https://${HOST}:${PORT}`);
});
app.yaml
runtime: nodejs12
service: api
handlers:
- url: /.*
script: auto
secure: always
redirect_http_response_code: 301
vpc_access_connector:
name:
env_variables:
NODE_ENV: production
PORT:8080
KEY: key.pem
CERT: cert.pem
...