This repository has been archived on 2024-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
tracman-server/config/routes/index.js

61 lines
1.4 KiB
JavaScript
Raw Normal View History

'use strict';
2017-04-10 01:00:56 -06:00
const mw = require('../middleware.js'),
router = require('express').Router(),
slug = require('slug'),
User = require('../models.js').user;
2017-03-14 22:05:03 -06:00
2017-03-18 12:46:02 -06:00
// Index
router.get('/', (req,res,next)=>{
2017-04-01 11:03:05 -06:00
res.render('index');
2017-03-18 12:46:02 -06:00
});
2016-03-31 15:57:34 -06:00
2017-03-18 11:21:48 -06:00
// Help
router.get('/help', mw.ensureAuth, (req,res)=>{
res.render('help');
});
2017-04-01 11:03:05 -06:00
// Terms of Service and Privacy Policy
router.get('/terms', (req,res)=>{
2017-04-01 11:03:05 -06:00
res.render('terms');
})
.get('/privacy', (req,res)=>{
2017-04-01 11:03:05 -06:00
res.render('privacy');
2017-03-18 11:21:48 -06:00
});
2017-04-10 01:00:56 -06:00
// robots.txt
router.get('/robots.txt', (req,res)=>{
2017-04-10 01:00:56 -06:00
res.type('text/plain');
res.send("User-agent: *\n"+
"Disallow: /map/*\n"
);
});
// favicon.ico
router.get('/favicon.ico', (req,res)=>{
2017-04-10 01:00:56 -06:00
res.redirect('/static/img/icon/by/16-32-48.ico');
});
// Endpoint to validate forms
router.get('/validate', (req,res)=>{
2017-04-10 01:00:56 -06:00
if (req.query.slug) { // validate unique slug
User.findOne( {slug:slug(req.query.slug)}, (err,existingUser)=>{
2017-04-10 01:00:56 -06:00
if (err) { console.log('/validate error:',err); }
2017-04-12 11:41:27 -06:00
if (existingUser && existingUser.id!==req.user) { res.sendStatus(400); }
2017-04-10 01:00:56 -06:00
else { res.sendStatus(200); }
} );
2017-04-10 01:00:56 -06:00
}
});
// Link to androidapp in play store
router.get('/android', (req,res)=>{
2017-04-10 01:00:56 -06:00
res.redirect('https://play.google.com/store/apps/details?id=us.keithirwin.tracman');
});
// Link to iphone app in the apple store
router.get('/ios', (req,res)=>{
2017-04-10 01:00:56 -06:00
res.sendStatus(404);
//TODO: Add link to info about why there's no ios app
});
2016-03-31 15:57:34 -06:00
module.exports = router;