-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.js
40 lines (31 loc) · 1.21 KB
/
routes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
API route middleware mounting
*/
const root = require("rootrequire");
const express = require("express");
const router = express.Router();
const cache = require(root + "/database/cache");
// Middleware for each API
const shop = require(root + "/apis/shop");
const analytics = require(root + "/apis/analytics");
module.exports = router;
// Shop
// Items
router.get("/shop/items/:id(\\d+)", cache(), shop.getItemById);
router.get("/shop/items/ids", shop.getItemIds);
// Orders
router.post("/shop/orders", shop.submitOrder);
// Analytics
router.get("/analytics/orders/ids", analytics.getOrderIds)
router.get("/analytics/orders/:id(\\d+)", cache(), analytics.getOrderById)
router.get("/analytics/items/top/:count(\\d+)", analytics.getTopItems);
router.get("/analytics/customers/top/:count(\\d+)", analytics.getTopCustomers);
// Customers
router.get("/analytics/customers/ids", analytics.getCustomerIds);
router.get("/analytics/customers/:id(\\d+)", cache(), analytics.getCustomerById);
router.get("/analytics/orders/:id(\\d+)", cache(), analytics.getOrderById);
router.get("/analytics/orders/:id(\\d+)/details", cache(), analytics.getOrderDetails);
// Catch all 404
router.all("*", (req, res, next) => {
res.sendStatus(404);
})