Created
May 1, 2019 09:18
-
-
Save ispyinternet/4da69f0be9145250ba27d61e69f1f76e to your computer and use it in GitHub Desktop.
sapper / aws-serverless-express
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
'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