Google App Engine错误-在此服务器上找不到请求的URL /

时间:2019-05-29 07:15:25

标签: google-app-engine

一切都可以在我的本地主机上正常运行,只是当我尝试将表单上传到Google App Engine时,我不断收到此404错误:

错误:未找到 在此服务器上找不到请求的URL/。

请忽略: 看起来您的帖子大部分是代码;请添加更多详细信息。 看起来您的帖子大部分是代码;请添加更多详细信息。 看起来您的帖子大部分是代码;请添加更多详细信息。 看起来您的帖子大部分是代码;请添加更多详细信息。 看起来您的帖子大部分是代码;请添加更多详细信息。 看起来您的帖子大部分是代码;请添加更多详细信息。

这是我的app.yaml文件

service: poforms
env: standard
runtime: nodejs10

handlers:
  - url: /poforms

    static_dir: build/static

  - url: /(.*\.(json|ico|js))$
    static_files: build/\1
    upload: build/.*\.(json|ico|js)$

  - url: .*
    static_files: build/index.html
    upload: build/index.html

Server.js

const nodemailer = require('nodemailer')
const path = require('path')
const express = require('express')
const app = express()
const http = require('http')
const server = http.createServer(app)
const port = 5000
const cors = require('cors')
app.use(cors())
const bodyParser = require('body-parser')
app.use(bodyParser.json())
const mailgunTransport = require('nodemailer-mailgun-transport')

// to support JSON-encoded bodies
app.use(
  bodyParser.urlencoded({
    // to support URL-encoded bodies
    extended: true
  })
)

app.get('/home', (req, res) => {
  console.log(
    'Hello from .get /home',
    req.body.generalDetails,
    req.body.firstName,
    req.body.mName
  )
})

app.post('/home', function (req, res) {
  const mailgun = require("mailgun-js");



  const DOMAIN = 'domain';
  const mg = mailgun({apiKey: 'apikey'
, domain: 'domain' });
  const message = {
    from: 'Tom <myemail>',
    to: 'myemail',
    subject: 'Registration form details',
    html:

    '<h1 style="color:red">Please find new Program orientation registrations details below</h1>' +


    '<p><strong>My Details</strong></p>' +
    '<br> <b>Preferred Name: </b> ' + '' + req.body.fName +
    '<br> <b>Middle Name: </b> ' + '' + req.body.mName +
    '<br> <b>Last Name: </b> ' + '' + req.body.lName +
    '<br> <b>Email Name: </b> ' + '' + req.body.email +


  };

  mg.messages().send(message, function (error, body) {
    console.log(body);
  });

  let data = [
    {
      // page one data
      generalDetails: req.body.generalDetails,
      fName: req.body.fName,
      mName: req.body.mName,
      lName: req.body.lName,
      email: req.body.email,

    }
  ]

  res.json(data)
})

app.listen(port, () => `Server running on port ${port}`)

App.js

import React, { Component } from "react";
import PageOne from "./components/PageOne";
import PageTwo from "./components/PageTwo";
import PageThree from "./components/PageThree";
import PageFour from "./components/PageFour";
import PageFive from "./components/PageFive";
import PageSix from "./components/PageSix";
import { Button } from "semantic-ui-react";
import "semantic-ui-css/semantic.min.css";
import axios from "axios";



class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      fName: "Text",
      lName: "Text",
      gender: "Text",
      email: '',



    };

    this.onContentChange = this.onContentChange.bind(this);
    this.onSubmitForm = this.onSubmitForm.bind(this);
  }

  render() {
    return (
      <div className="App">
        <PageOne handleChange={this.onContentChange} />
        <PageTwo handleChange={this.onContentChange} />
        <PageThree handleChange={this.onContentChange} />
        <PageFour handleChange={this.onContentChange} />
        <PageFive handleChange={this.onContentChange} />
        <PageSix handleChange={this.onContentChange} />

        <Button onClick={this.onSubmitForm}
        style={{
          marginLeft: 700,
        }}
        >Submit Form</Button>

        <br />
        <br />
      </div>
    );
  }

  onSubmitForm = e => {
  e.preventDefault();


    var data = {
      fName: this.state.fName,
      mName: this.state.mName,
      lName: this.state.lName,
      email: this.state.email,


    };




    axios
  .post("http://localhost:5000/home", data)
  .then(result => {
    console.log(result)
  })
  .catch(() => {
    console.log("Something went wrong. Please try again later");
  });


  };



  //end

  onContentChange(fieldname, data) {
    console.log("On Content Change", data);

    this.setState({
      [fieldname]: data
    });

  }
}

export default App;

0 个答案:

没有答案