0

I deployed a nodejs web server to GAE flexible environment.

When I access my web server, it using https protocol.

I try to use http protocol, but it seems can not be accessed.

Does GAE support http?

I expect both http and https should work fine.

update 1

app.yaml

runtime: nodejs8
env_variables:
  NODE_ENV: production
  PORT: 8080

app.flex.yaml

service: get-started-flex
runtime: nodejs
env: flex
env_variables:
  NODE_ENV: production
manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10

server.js

const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const package = require('./package.json');

console.log('version: ', package.version);
console.log('process.env.NODE_ENV: ', process.env.NODE_ENV);

const app = express();
app.use(bodyParser.urlencoded({ extended: true }));

app.get('/', (req, res) => {
  res.send(`Hello from App Engine! version:${package.version}`);
});

app.get('/submit', (req, res) => {
  res.sendFile(path.join(__dirname, '/views/form.html'));
});

app.post('/submit', (req, res) => {
  console.log({
    name: req.body.name,
    message: req.body.message
  });
  res.send('Thanks for your message!');
});

// Listen to the App Engine-specified port, or 8080 otherwise
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
  console.log(`Server listening on port ${PORT}...`);
});
Lin Du
  • 88,126
  • 95
  • 281
  • 483

1 Answers1

2

In App Engine Standard you have the option to state the security of each handler by using the secure tag, however, in Flexible this is not possible.

Besides, in Flexible you can do http and http requests to the handlers but with some restrictions. Note that the application knows what protocol to use depending on the X-Forwarded-Proto header of the request, as you can see in this documentation.

However, I believe you can change this behaviour on the application level of your app. My guess is that you are enforcing https in some part of your application, for example, if you have the line require("https") in your application.

Also, I have found this answer that could help in your case. If you disable SSL security checks in your handler, you might be able to process the requests even if the connection is not secure, but this will make your application insecure.

Joan Grau Noël
  • 3,084
  • 12
  • 21
  • It seems app engine flexible environment does not support `wss`, https://stackoverflow.com/a/44557449/6463558, so I am looking for a way to using `http` in `GAE` flexible environment in order to using `ws://` instead of `wss://`. Just for testing. BTW, I am using `socket.io`. In my application, I did't use `https.createServer` or something. Just a simple http server – Lin Du Jan 21 '19 at 11:37
  • Can you share your code to take a look at it? It would also help me reproduce the issue. – Joan Grau Noël Jan 23 '19 at 10:39
  • Updated. Please take a look. – Lin Du Jan 24 '19 at 02:31
  • I found a reason. My company network use `websense `, so when I try to access my site using `http` protocol. I found there is a pending request in chrome `network` tab. `http://172.31.6.23:15871/cgi-bin/blockpage.cgi?ws-session=4127644080`. Because browser try to redirect to this `blockpage`, and for some reason, it can't be loaded. I will try it at home. – Lin Du Jan 24 '19 at 03:05