找不到快速路由-404错误

时间:2018-10-18 06:48:42

标签: html node.js apache express

我正在创建一个简单的联系表单,并使用nodejs和express处理后端。我使用适当的动作(“ /接触”)实现了我的表单,并实现了角度路线。每当我提交表单时,都会出现错误:

{
"short_name": "MyApp",
"name": "My Progressive App",
"icons": [
    {
        "src": "/img/splash/48x48.png",
        "type": "image/png",
        "sizes": "48x48"
    },
    {
        "src": "/img/splash/96x96.png",
        "type": "image/png",
        "sizes": "96x96"
    },
    {
        "src": "/img/splash/144x144.png",
        "type": "image/png",
        "sizes": "144x144"
    },
    {
        "src": "/img/splash/192x192.png",
        "type": "image/png",
        "sizes": "192x192"
    },
    {
        "src": "/img/splash/256x256.png",
        "type": "image/png",
        "sizes": "256x256"
    },
    {
        "src": "/img/splash/384x384.png",
        "type": "image/png",
        "sizes": "384x384"
    },
    {
        "src": "/img/splash/512x512.png",
        "type": "image/png",
        "sizes": "512x512"
    }
],
"background_color": "#FFFFFF",
"display": "standalone",
"theme_color": "#FFFFFF"
}

index.js:

The requested URL /contact was not found on this server.

index.html:

// POST route from contact form
app.post('/contact', function (req, res) {
  let mailOpts, smtpTrans;
  smtpTrans = nodemailer.createTransport({
    host: 'smtp.gmail.com',
    port: 465,
    secure: true,
    auth: {
      user: GMAIL_USER,
      pass: GMAIL_PASS
    }
  });
  mailOpts = {
    from: req.body.name + ' <' + req.body.email + '>',
    to: GMAIL_USER,
    subject: 'New message from contact form at tylerkrys.ca',
    text: `${req.body.name} (${req.body.email}) says: ${req.body.message}`
  };
  smtpTrans.sendMail(mailOpts, function (error, response) {
    if (error) {
      res.render('contact-failure');
    }
    else {
      res.render('contact-success');
    }
  });
});

我正在使用debian 4.9.88在APACHE服务器上运行。我查看了有关此问题的其他表格,并尝试在/ public_html /根目录中实现以下.htaccess文件:

<form action="/contact" id="contact-form" method="post" role="form">
            <h2 class="text-center">Contact us</h2>
            <div class="form-group"><input class="form-control" type="text" id="name" name="name" placeholder="Name" required="required"></div>
            <div class="form-group"><input class="form-control is-invalid" type="email" id="email" name="email" placeholder="Email" required="required"><small class="form-text text-danger">Please enter a correct email address.</small></div>
            <div class="form-group"><textarea class="form-control" rows="14" id="message" name="message" placeholder="Message" required="required"></textarea></div>
            <div class="form-group"><button class="btn btn-primary" type="submit">Send </button></div>
        </form>

但是,这不能解决问题。这也是由于我对路线的工作原理一无所知(我阅读了有关角度的文档,但是仍然难以理解为什么找不到/ contact路径)。

更新:显然,在更改我的.htaccess文件时,我需要将apache配置更改为“ AllowOverride All”,并且不再出现404错误,但实际的路由仍未触发。我只是重定向到我的index.html页面:“ www.SITE.com/contact”,将对此提供任何帮助。

0 个答案:

没有答案