ariketa-03/index.js

31 lines
820 B
JavaScript
Raw Permalink Normal View History

2021-03-16 20:09:37 +01:00
const express = require('express');
const app = express();
const path = require('path');
2021-04-20 16:24:53 +02:00
const bodyParser= require('body-parser');
const cookieParser = require('cookie-parser');
const routes = require('./routes');
const api = require('./routes/api');
2021-03-16 20:09:37 +01:00
app.set('port', 8080);
2021-04-24 13:05:36 +02:00
app.set('views', __dirname + '/views');
2021-04-20 16:24:53 +02:00
app.set('view engine', 'pug');
2021-03-16 20:09:37 +01:00
app.use(express.static(path.join(__dirname, 'public')));
2021-04-20 16:24:53 +02:00
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(cookieParser());
2021-03-16 20:09:37 +01:00
2021-04-20 16:24:53 +02:00
app.get('/', routes.index);
2021-03-16 20:09:37 +01:00
2021-04-20 16:24:53 +02:00
app.get('/:name', routes.partials);
2021-03-16 20:09:37 +01:00
app.get('*', (req, res, next) => {
res.status(200).send('Eskatu duzun orrialdea ez da aurkitu!');
next();
});
2021-04-20 16:24:53 +02:00
app.post('/',api.login);
2021-03-16 20:09:37 +01:00
app.listen(app.get('port'), () => {
console.log('Zerbitzaria martxan ' + app.get('port') + ' atakan');
});