Answer the question
In order to leave comments, you need to log in
Express js what's wrong with routing?
Good day.
Guys, tell me what's wrong with my code, I wrote so to speak on the off-doc.
At first I sinned on the EJS template engine, but after disabling it, nothing has changed.
Just in case, the logic of actions was the following:
1 There is an index.ejs page ( if it is a view ), it has a link to the auth.ejs
registration page
2 There, respectively, a form with the POST
method
3 Submit and it's done ...
But !!! When you click on the link, everything is sad...
Cannot GET /auth
THANK YOU IN ADVANCE!!!
const express = require('express');
const bodyParser = require('body-parser');
const routes = require('./routes/index');
const app = express();
// use EJS in views
app.set('view engine', 'ejs');
// configure app
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// routes
app.get('/', (req, res) => res.render('index'));
app.use('/auth', routes.auth);
module.exports = app;
const auth = require('./auth');
module.exports = {
auth
};
const express = require('express');
const router = express.Router();
router.get('/auth', (req, res) => res.render('/auth'));
router.post('/auth', (res, req) => {
console.log(req.body);
res.json({
ok: true
});
});
module.exports = router;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question