-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.js
46 lines (37 loc) · 1009 Bytes
/
handler.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
require("dotenv").config();
const serverless = require("serverless-http");
const express = require("express");
const app = express();
// api json
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
// mongoose connect
const mongoose = require("./config/mongoose");
mongoose.connect();
// enable this if use redis stack
// require("./app/helpers/redis.helper");
const Redis = require("ioredis");
const redis = new Redis(process.env.REDIS_URL);
global.redis = redis;
// cors
const cors = require("cors");
app.use(cors());
// lodash
const _ = require("lodash");
global._ = _;
// routes
const routes = require("./routes");
app.use("/", routes);
const slsHandler = serverless(app);
// cronjob
const slsCronHandler = async (event, context) => {
// TODO: define the path to cron here
// event.path = "/fb/friends/fetch";
const result = await slsHandler(event, context);
return result;
};
module.exports = {
serverless: slsHandler,
cron: slsCronHandler,
default: app,
};