Skip to content

Instantly share code, notes, and snippets.

View danielkhan's full-sized avatar

Daniel Khan danielkhan

  • Sentry
  • Linz / Austria
  • X @dkhan
View GitHub Profile
# The name of the service
service: dynatrace-lambda-sample
provider:
name: aws
# The node version to use
runtime: nodejs8.10
functions:
hello:
const axios = require('axios');
module.exports.handler = async (event, context, callback) => {
// Asynchronous HTTP GET
// In real projects, you want to add some error handling here.
const res = axios.get('https://api.weather.gov/points/39.7456,-97.0892');
const response = {
statusCode: 200,
# The name of the service
service: dynatrace-lambda-sample
provider:
name: aws
# The node version to use
runtime: nodejs8.10
functions:
hello:
console.log('Loading function');
const doc = require('dynamodb-doc');
const dynamo = new doc.DynamoDB();
/**
* Demonstrates a simple HTTP endpoint using API Gateway. You have full
* access to the request and response payload, including headers and
router.post('/login', async (req, res) => {
try {
return passport.authenticate('local', { session: false }, (err, user) => {
if (err || !user) {
res.status(404).json({ error: 'Invalid username or password' });
}
return req.login(user, { session: false }, (loginErr) => {
if (loginErr) {
res.status(500).json({ error: loginErr });
}
const mongoose = require('mongoose');
const ContactSchema = mongoose.Schema({
user_id: {
type: mongoose.Schema.ObjectId,
required: true,
},
firstname: {
type: String,
required: true,
const passport = require('passport');
const passportJWT = require('passport-jwt');
const JWTStrategy = passportJWT.Strategy;
const ExtractJWT = passportJWT.ExtractJwt;
const LocalStrategy = require('passport-local').Strategy;
const UserService = require('../services/UserService');
module.exports = (config) => {
module.exports = {
"extends": "airbnb-base",
"rules": {
"no-unused-vars": ["error", { "argsIgnorePattern": "next" }],
"no-underscore-dangle": ["error", { "allow": ["_id"] }],
"no-param-reassign": ["error", { "props": false }],
}
};
/**
* @swagger
* /users/register:
* post:
* parameters:
* - in: body
* name: user
* description: The user to create.
* schema:
* $ref: "#/definitions/User"
UserSchema.pre('save', function preSave(next) {
const user = this;
// only hash the password if it has been modified (or is new)
if (!user.isModified('password')) return next();
// generate a salt
return bcrypt.genSalt(10, (err, salt) => {
if (err) return next(err);