This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
FunctionProject/website/server.js

29 lines
674 B
JavaScript
Raw Normal View History

/* Modules */
2020-08-03 12:04:07 +02:00
const next = require('next')
const express = require('express')
const redirectToHTTPS = require('express-http-to-https').redirectToHTTPS
2020-03-22 03:52:04 +01:00
/* Variables */
2020-08-03 12:04:07 +02:00
const PORT = process.env.PORT || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
2020-03-22 03:52:04 +01:00
app.prepare().then(() => {
2020-08-03 12:04:07 +02:00
const server = express()
2020-03-22 03:52:04 +01:00
2020-08-03 12:04:07 +02:00
/* Middlewares */
server.use(redirectToHTTPS([/localhost:(\d{4})/]))
2020-08-03 12:04:07 +02:00
/* Routes */
server.all('*', (req, res) => {
return handle(req, res)
})
2020-08-03 12:04:07 +02:00
/* Server */
server.listen(PORT, (error) => {
if (error) throw error
console.log(`> Ready on http://localhost:${PORT}`)
})
})