1
0
mirror of https://github.com/nolanlawson/pinafore synced 2024-12-13 02:37:20 +01:00
Pinafore-Web-Client-Frontend/server.js
2018-03-20 20:46:37 -07:00

28 lines
669 B
JavaScript

const app = require('express')()
const compression = require('compression')
const sapper = require('sapper')
const serveStatic = require('serve-static')
const { PORT = 4002 } = process.env
// this allows us to do e.g. `fetch('/_api/blog')` on the server
const fetch = require('node-fetch')
global.fetch = (url, opts) => {
if (url[0] === '/') url = `http://localhost:${PORT}${url}`
return fetch(url, opts)
}
app.use(compression({ threshold: 0 }))
app.use(serveStatic('assets', {
setHeaders: (res) => {
res.setHeader('Cache-Control', 'public,max-age=14400')
}
}))
app.use(sapper())
app.listen(PORT, () => {
console.log(`listening on port ${PORT}`)
})