ariketa-02/index.js

41 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-03-05 16:45:05 +01:00
const express = require('express');
const app = express();
const path = require('path');
2021-03-31 22:48:53 +02:00
const bodyParser= require('body-parser');
2021-03-05 16:45:05 +01:00
app.set('port', 8080);
app.use(express.static(path.join(__dirname, 'public')));
app.use('/images', express.static(path.join(__dirname, 'public/images')));
2021-03-28 15:58:49 +02:00
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
2021-03-05 16:45:05 +01:00
app.get('/', (req, res) => {
res.status(200).sendFile(__dirname + '/index.html');
});
app.get('/irudiak', (req, res) => {
res.status(200).sendFile(__dirname + '/irudiak.html');
});
app.get('/irudi_:num', (req, res) =>{
var num = req.params.num;
res.status(200).sendFile(__dirname + '/irudi_'+num+'.html');
});
app.get('*', (req, res, next) => {
res.status(200).send('Eskatu duzun orrialdea ez da aurkitu!');
next();
});
2021-03-28 15:58:49 +02:00
app.post('/',(req, res) => {
console.log(req.body);
if(req.body.username != ''){
res.cookie('username', req.body.username, { expires: new Date(Date.now() + 900000), 'sameSite':'lax'})
}
res.status(200).sendFile(__dirname + '/index.html');
});
2021-03-05 16:45:05 +01:00
app.listen(app.get('port'), () => {
console.log('Zerbitzaria martxan ' + app.get('port') + ' atakan');
});