Created
July 7, 2019 03:53
-
-
Save evdama/54ea8405a8abae4df0ff9c84603f7fc7 to your computer and use it in GitHub Desktop.
the server including helmet and sapper middleware
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 './css/tailwind.css'; | |
import * as sapper from '@sapper/server'; | |
import compression from 'compression'; | |
import express from 'express'; | |
import helmet from "helmet"; | |
import sirv from 'sirv'; | |
const { | |
PORT, | |
NODE_ENV | |
} = process.env; | |
const dev = NODE_ENV === 'development'; | |
const app = express(); | |
if ( dev ) app.use( sirv( 'static', { dev } ) ); | |
// TODO: enable content security policy with helmet https://helmetjs.github.io/docs/csp/ | |
app.use( | |
helmet(), | |
sapper.middleware(), | |
compression({ threshold: 0 }) | |
); | |
if ( dev ) { | |
// only listen when started in dev | |
app.listen( PORT, err => { | |
if ( err ) console.log( 'error', err ); | |
} ); | |
} | |
export { | |
app | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment