Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ispyinternet/4da69f0be9145250ba27d61e69f1f76e to your computer and use it in GitHub Desktop.
Save ispyinternet/4da69f0be9145250ba27d61e69f1f76e to your computer and use it in GitHub Desktop.
sapper / aws-serverless-express
'use strict'
if (process.env.DEBUG == 'development') {
setTimeout(() => { console.log("ENV", process.env) }, 1000);
}
import sirv from 'sirv';
import express from 'express';
import { Store } from 'svelte/store.js';
import session from './DynamoDBSession.js';
import * as sapper from '../__sapper__/server.js';
import fetch from 'node-fetch';
import bodyParser from 'body-parser';
import awsServerlessExpress from 'aws-serverless-express';
import config from '@helpers/auth/config.js';
import { auth, storage as authStore } from '@helpers/auth';
// make aws-amplify auth work on server
global.fetch = fetch;
const app = express();
app.set('trust proxy', true)
app.use(
sirv('static'),
session,
bodyParser.json({ type: 'application/json' }),
sapper.middleware({
store: req => {
let awsAuth = req.session.awsAuth ? req.session.awsAuth : {};
let store = req.session.store ? req.session.store : {};
authStore.init(awsAuth)
return new Store({ awsAuth, store })
}
}))
if (process.env.NODE_ENV == 'development' || process.env.SAPPER_EXPORT) {
console.log(process.env)
console.log("listening on - ", process.env.PORT);
app.listen(process.env.PORT);
}
export default app;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment