fedilove-ui/server.js

24 lines
576 B
JavaScript
Raw Normal View History

2018-02-09 06:29:29 +00:00
const app = require('express')()
const compression = require('compression')
const sapper = require('sapper')
const serveStatic = require('serve-static')
2018-01-06 23:51:25 +00:00
2018-02-09 06:29:29 +00:00
const { PORT = 4002 } = process.env
2018-01-06 23:51:25 +00:00
2018-02-08 16:22:14 +00:00
// this allows us to do e.g. `fetch('/_api/blog')` on the server
2018-02-09 06:29:29 +00:00
const fetch = require('node-fetch')
2018-01-06 23:51:25 +00:00
global.fetch = (url, opts) => {
2018-02-09 06:29:29 +00:00
if (url[0] === '/') url = `http://localhost:${PORT}${url}`
return fetch(url, opts)
}
2018-01-06 23:51:25 +00:00
2018-02-09 06:29:29 +00:00
app.use(compression({ threshold: 0 }))
2018-01-06 23:51:25 +00:00
2018-02-09 06:29:29 +00:00
app.use(serveStatic('assets'))
2018-01-06 23:51:25 +00:00
2018-02-09 06:29:29 +00:00
app.use(sapper())
2018-01-06 23:51:25 +00:00
app.listen(PORT, () => {
2018-02-09 06:29:29 +00:00
console.log(`listening on port ${PORT}`)
})