fix: add robots.txt

This commit is contained in:
dsrkafuu 2022-03-13 20:57:42 +08:00
parent 2cc359bd42
commit e6b6f547bb
2 changed files with 19 additions and 2 deletions

View File

@ -3,15 +3,17 @@ import { genErrorResponse, ResError } from './response';
import { withCORS } from './middlewares';
import * as index from './routes/index';
import * as favicon from './routes/favicon';
import * as robots from './routes/robots';
import * as image from './routes/image';
import * as api from './routes/api';
const router = Router();
router.options('*', withCORS);
// routes
router.get('/', index.get);
router.get('/favicon.ico', favicon.get);
router.get('/robots.txt', robots.get);
// routes
router.get('/:id', image.get);
router.get('/api/:id', api.get);
// router.delete('/api/:id', api.del);

15
src/routes/robots.js Normal file
View File

@ -0,0 +1,15 @@
import { genResponse } from '../response';
/**
* @param {Request} req
*/
export async function get(req) {
const robots = 'User-agent: *\nDisallow: /';
return await genResponse(req, robots, {
status: 200,
headers: {
'Content-Type': 'text/plain; charset=utf-8',
'Cache-Control': 'public, max-age=86400',
},
});
}