-
-
Save vital-edu/15c2fbcc3fb66aa8c3bb9a9f8019a84b to your computer and use it in GitHub Desktop.
Ref
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import verifyJwt from 'security'; | |
import logger from 'logger'; | |
import model from 'model'; | |
function handlePostRequest(request) { | |
if (request.headers.authorization === null) { | |
throw Error('Unauthorized'); | |
} | |
if (!verifyJwt(request.headers.authorization)) { | |
throw Error('Unauthorized'); | |
} | |
// Handling post request | |
model.save(request.payload); | |
var logMessage = `POST - ${request.url} - ${new Date().toISOString}`; | |
var log = logger.createNewLogEntry(); | |
log.add(logMessage); | |
log.save(); | |
return 'OK'; | |
} | |
function handleGetRequest(request) { | |
if (request.headers.authorization === null) { | |
throw Error('Unauthorized'); | |
} | |
if (!verifyJwt(request.headers.authorization)) { | |
throw Error('Unauthorized'); | |
} | |
// Handling post request | |
var list = model.fetch(request.payload); | |
var logMessage = `GET - ${request.url} - ${new Date().toISOString}`; | |
var log = logger.createNewLogEntry(); | |
log.add(logMessage); | |
log.save(); | |
return list; | |
} |
Author
vital-edu
commented
Jun 17, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment