-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
42 lines (30 loc) · 1.02 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
import express, { json } from "express";
import dotenv from "dotenv";
import { config } from "serpapi";
import cors from "cors";
import {getResults, postResults, search } from './search.js';
dotenv.config();
// console.log(process.env);
config.api_key = process.env.SERPAPI_KEY;
const app = express();
app.use(cors({ origin: "http://yourdomain.com" }));
app.use(json());
const PORT = process.env.PORT || 3000;
app.get("/", (req, res) => {
res.status(200).json({ message: "response to default get request" });
});
app.get("/another-route", (req, res) => {
res.status(200).json({ message: "here is another route" });
});
app.get("/keyword-search/:q", search, (req, res) => {
res.status(200).json(res.locals.result);
});
app.get("/search", getResults, search, (req, res) => {
res.status(200).json(res.locals.result);
});
app.post("/search", postResults, search, (req, res) => {
res.status(200).json(res.locals.result);
});
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}\n-------------------------`);
});