2021-06-23 12:15:14 +00:00
|
|
|
const { join } = require('path');
|
2021-05-19 15:17:24 +00:00
|
|
|
const express = require('express');
|
2021-11-11 15:18:31 +00:00
|
|
|
const { errorHandler } = require('./middleware');
|
2021-05-19 15:17:24 +00:00
|
|
|
|
|
|
|
const api = express();
|
|
|
|
|
2021-06-07 11:40:51 +00:00
|
|
|
// Static files
|
2021-06-23 12:15:14 +00:00
|
|
|
api.use(express.static(join(__dirname, 'public')));
|
|
|
|
api.use('/uploads', express.static(join(__dirname, 'data/uploads')));
|
2021-06-07 11:40:51 +00:00
|
|
|
api.get(/^\/(?!api)/, (req, res) => {
|
2021-06-23 12:15:14 +00:00
|
|
|
res.sendFile(join(__dirname, 'public/index.html'));
|
2021-08-06 14:16:13 +00:00
|
|
|
});
|
2021-06-23 12:15:14 +00:00
|
|
|
|
2021-05-19 15:17:24 +00:00
|
|
|
// Body parser
|
|
|
|
api.use(express.json());
|
|
|
|
|
|
|
|
// Link controllers with routes
|
|
|
|
api.use('/api/apps', require('./routes/apps'));
|
|
|
|
api.use('/api/config', require('./routes/config'));
|
|
|
|
api.use('/api/weather', require('./routes/weather'));
|
2021-05-22 17:04:34 +00:00
|
|
|
api.use('/api/categories', require('./routes/category'));
|
2021-05-23 15:18:04 +00:00
|
|
|
api.use('/api/bookmarks', require('./routes/bookmark'));
|
2021-10-11 11:03:31 +00:00
|
|
|
api.use('/api/queries', require('./routes/queries'));
|
2021-11-11 15:01:56 +00:00
|
|
|
api.use('/api/auth', require('./routes/auth'));
|
2022-03-24 13:48:10 +00:00
|
|
|
api.use('/api/themes', require('./routes/themes'));
|
2021-05-19 15:17:24 +00:00
|
|
|
|
|
|
|
// Custom error handler
|
|
|
|
api.use(errorHandler);
|
|
|
|
|
2021-08-06 14:16:13 +00:00
|
|
|
module.exports = api;
|