forked from paritytech/sms-verification
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (26 loc) · 872 Bytes
/
index.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
'use strict'
const express = require('express')
const hsts = require('hsts')
const corser = require('corser')
const noCache = require('nocache')()
const bodyParser = require('body-parser')
const config = require('config')
const spdy = require('spdy')
const fs = require('fs')
const verify = require('./verify')
const api = express()
module.exports = api
api.use(hsts({maxAge: 3 * 24 * 60 * 60 * 1000})) // 3 days
// CORS
const allowed = corser.simpleRequestHeaders.concat(['User-Agent'])
api.use(corser.create({requestHeaders: allowed}))
api.use(bodyParser.json())
api.post('/:number', noCache, verify)
const server = spdy.createServer({
cert: fs.readFileSync(config.http.cert),
key: fs.readFileSync(config.http.key)
}, api)
server.listen(config.http.port, (err) => {
if (err) return console.error(err)
console.info(`Listening on ${config.http.port}.`)
})