-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.js
46 lines (35 loc) · 1.41 KB
/
server.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
41
42
43
44
45
46
import * as Environment from "~/node_common/environment";
import * as ScriptLogging from "~/node_common/script-logging";
import * as Data from "~/node_common/data";
import * as Serializers from "~/node_common/serializers";
import * as Websocket from "~/node_common/nodejs-websocket";
import * as Search from "~/node_common/search-v4";
import express from "express";
import bodyParser from "body-parser";
import cors from "cors";
const server = express();
//make it so can only access with a proper API key (JWT.verify)
const LENS = "SERVER START ";
Websocket.create();
server.use(bodyParser.json());
server.use(cors());
server.get("/favicon.ico", (req, res) => res.status(204));
server.get("/", async (req, res) => {
ScriptLogging.message(LENS, "fetching serialized users and slates");
return res.status(200).json({
decorator: "LENS",
data: "lens operational!",
});
});
server.get("/:query", async (req, res) => {
let searchResults = Search.search(req.params.query);
return res.status(200).json({ decorator: "LENS", data: { results: searchResults } });
});
server.post("/search", async (req, res) => {
let searchResults = await Search.search(req.body.data.query, req.body.data.type);
return res.status(200).json({ decorator: "LENS", data: { results: searchResults } });
});
server.listen(Environment.PORT, (e) => {
if (e) throw e;
ScriptLogging.log(LENS, `http://localhost:${Environment.PORT}`);
});