Я пытаюсь создать свое первое приложение самостоятельно, но go не могу решить эту проблему. Буду очень признателен, если кто-нибудь поможет разобраться в чем проблема. После нажатия кнопки отправки я получаю сообщение об ошибке Cannot POST /. Подозреваю, что ошибка банальная и меня это раздражает. На мой взгляд, проблема в моем файле маршрута.
Вот мой html form
(записано в ejs
):
<%- include('includes/start.ejs') %>
<%- include('includes/navbar.ejs') %>
<div class="container">
<p>Here you can create your Tournament!</p>
<form class="form" action="/" method="POST">
<label>Discypline:</label><br>
<input type="text" name="discipline" placeholder="E.G. Chess"><br><br>
<label for="lname">Tournament type:</label><br>
<select name="type">
<option value="Bracket Tournament">Bracket Tournament</option>
<option value="League Tournament">League Tournament</option>
</select><br><br>
<label>Description of Tournament:</label><br>
<textarea name="description" rows="4" cols="50"></textarea><br><br>
<input type="submit" value="Submit"><br>
</form>
<%- include('includes/end.ejs') %>
</div>
Вот мой route
файл:
const express = require('express');
const router = express.Router();
const bodyParser = require('body-parser');
router.use(bodyParser.urlencoded({extended: false}));
router.use(bodyParser.json());
const Tournament = require('../models/tournament.js')
router.get('/creator', (req, res, next) => {
res.render('../views/creator.ejs');
});
router.post('/creator', (req, res, next) => {
//const tournament = new Tournament()
console.log(req.body.discipline);
return;
});
module.exports = router;
А вот мой app
код:
const express = require('express');
const app = express();
const path = require('path');
const homeRouter = require('.//routes/home.js');
const creatorRouter = require('.//routes/creator.js');
app.set('view engine', 'ejs');
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', homeRouter);
app.use('/', creatorRouter);
app.listen(3000);
Спасибо за помощь. С уважением.