-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
60 lines (48 loc) · 1.29 KB
/
app.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
47
48
49
50
51
52
53
54
55
56
57
'use strict'
const fastify = require('fastify')({logger: false})
const path = require('path')
const AutoLoad = require('fastify-autoload')
// store application root
global.__basedir = __dirname
const dotEnv = require('dotenv').config()
/*
fastify.register(
require('fastify-rate-limit'), {
max: 60,
timeWindow: '1 minute'
})
*/
fastify.register(
require('fastify-helmet'), {
hidePoweredBy: {
setTo: '1app4pt API Server'
}
})
const corsOptions = {
origin: process.env.CORS_ORIGIN.split(','),
methods: 'OPTIONS,GET,HEAD,PUT,PATCH,POST,DELETE',
optionsSuccessStatus: 200 // to support some legacy browsers
}
fastify.use(require('cors')(corsOptions))
fastify.register(AutoLoad, {
dir: path.join(__dirname, 'plugins'),
//options: Object.assign({}, opts)
})
fastify.register(AutoLoad, {
dir: path.join(__dirname, 'controllers/v1'),
options: Object.assign({}, { prefix: '/api/v1' })
})
fastify.register(require('fastify-axios'))
// Support for AWS Lambda
if (process.env.AWS_EXECUTION_ENV) {
const serverless = require('serverless-http');
module.exports.handler = serverless(fastify);
} else {
fastify.listen(process.env.PORT, err => {
if (err) {
console.log(err);
process.exit(1);
}
console.log(`server listening on ${fastify.server.address().port}`);
})
}