Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const middlewares = [
middleware.eventContext(),
/* get userId from event */ (req, res, next) => {
try {
req.userId = req.apiGateway.event.requestContext.authorizer.sub
} catch (err) {
req.userId = null
console.warn(err.stack || err)
}
next()
}
]
// Create a server for a API instance
const server = adapter.createServer(apiFactory(repo, middlewares))
module.exports.handler = (event, context, callback) => {
// NOTE: aws-serverless-express uses context.succeed, but AWS already
// deprecated it in favor of callback
const fakeContext = {
succeed: res => callback(null, res)
}
// Proxy the actual request
adapter.proxy(server, event, fakeContext)
}
exports.handler = (event, context, callback) => {
if (process.env.LAMBDA_DEBUG_LOG) {
console.log('LAMBDA EVENT', event)
}
if (!event.command) {
// default web server stuff
const app = require('./build/server/server/index')
const server = awsServerlessExpress.createServer(app.default)
const startTime = (context.getRemainingTimeInMillis ? context.getRemainingTimeInMillis() : 0)
const webResponse = awsServerlessExpress.proxy(server, event, context)
if (process.env.DEBUG_SCALING) {
const endTime = (context.getRemainingTimeInMillis ? context.getRemainingTimeInMillis() : 0)
// confusingly, we do start - end, instead of the reverse,
// because it's *remaining* time which counts down
if ((startTime - endTime) > 3000) { //3 seconds
console.log('SLOW_RESPONSE milliseconds:', startTime-endTime, event)
}
}
return webResponse
} else if (event.command === 'ping') {
// no-op ping to keep server active, where useful, e.g. Amazon Lambda.
callback()
} else {
// handle a custom command sent as an event
// default routes
app.use('/', router);
// global 404 response when page is not found
app.use((req, res) => {
res.boom.notFound('requested page not found');
});
// catch all error handling
app.use((err, req, res, _next) => {
res.error = JSON.stringify(err, Object.getOwnPropertyNames(err));
return res.boom.badImplementation('Something broke!');
});
const server = awsServerlessExpress.createServer(app, null);
module.exports = {
app,
handler: (event, context) => awsServerlessExpress.proxy(server, event, context)
};
const awsServerlessExpress = require('aws-serverless-express');
const app = require('./index');
const server = awsServerlessExpress.createServer(app);
exports.runserver = (event, context) => {
console.log("EVENT: " + JSON.stringify(event));
awsServerlessExpress.proxy(server, event, context)
}
'use strict';
const awsServerlessExpress = require('aws-serverless-express')
const app = require('./app')
const server = awsServerlessExpress.createServer(app)
module.exports.auth0Authentication = (event, context) => awsServerlessExpress.proxy(server, event, context);
'use strict';
const awsServerlessExpress = require('aws-serverless-express')
const app = require('./app')
const server = awsServerlessExpress.createServer(app)
module.exports.auth0Authentication = (event, context) => awsServerlessExpress.proxy(server, event, context);
'use strict';
const awsServerlessExpress = require('aws-serverless-express');
const app = require('./src/app');
const server = awsServerlessExpress.createServer(app);
exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context);
'text/xml',
]
const app = asyncify(express())
app.use(nocache())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(cookieParser())
app.use(api)
app.get('/', (index as any).render)
app.get('/_error', (error as any).render)
const server = awsServerlessExpress.createServer(app, undefined, BINARY_MIME_TYPES)
export const handler = (event: any, context: Context) => {
return awsServerlessExpress.proxy(server, event, context)
}
.then(() => serverless.createServer(expressApp));
}
'use strict'
const awsServerlessExpress = require('aws-serverless-express');
const app = require('./src/app');
const server = awsServerlessExpress.createServer(app);
exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context);