Lin Du
Lin Du

Reputation: 102337

Can I access app engine service by using http protocol?

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}...`);
});

Upvotes: 0

Views: 70

Answers (1)

Joan Grau Noël
Joan Grau Noël

Reputation: 3192

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.

Upvotes: 2

Related Questions