40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
|
const express = require('express');
|
||
|
const app = express();
|
||
|
const path = require('path');
|
||
|
const bodyParser= require('body-parser');
|
||
|
|
||
|
app.set('port', 8080);
|
||
|
app.use(express.static(path.join(__dirname, 'public')));
|
||
|
app.use(bodyParser.urlencoded({extended: true}));
|
||
|
app.use(bodyParser.json());
|
||
|
|
||
|
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();
|
||
|
});
|
||
|
|
||
|
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');
|
||
|
});
|
||
|
|
||
|
app.listen(app.get('port'), () => {
|
||
|
console.log('Zerbitzaria martxan ' + app.get('port') + ' atakan');
|
||
|
});
|