-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathCatalogApi.js
More file actions
34 lines (27 loc) · 888 Bytes
/
CatalogApi.js
File metadata and controls
34 lines (27 loc) · 888 Bytes
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
(function () {
"use strict";
let express = require("express");
let videoDatabase = require("./VideoDatabase");
module.exports = {
"createRouter": function createRouter() {
let router = express.Router();
// This API call returns a JSON list with basic info about all the videos on the website.
router.get("/videos", function processGet(request, response) {
// We do not want our API calls to get cached.
response.header("Cache-Control", "no-cache");
let videoList = [];
videoDatabase.getAllVideos().forEach(function mapVideo(video) {
// Only name, URL and an optional list tags are exposed to the browser.
// Everything else is for internal use only.
videoList.push({
"name": video.name,
"url": video.url,
"tags": video.tags
});
});
response.json(videoList);
});
return router;
}
};
})();