mirror of
https://github.com/cupcakearmy/obolus.git
synced 2025-09-06 08:10:39 +00:00
client
This commit is contained in:
33
www/server.js
Executable file
33
www/server.js
Executable file
@@ -0,0 +1,33 @@
|
||||
const { createServer } = require('http')
|
||||
const httpProxy = require('http-proxy')
|
||||
const { parse } = require('url')
|
||||
const next = require('next')
|
||||
const axios = require('axios')
|
||||
|
||||
// Initialize globals
|
||||
axios.defaults.validateStatus = status => status < 500
|
||||
|
||||
const dev = process.env.NODE_ENV !== 'production'
|
||||
const app = next({ dev })
|
||||
const handle = app.getRequestHandler()
|
||||
|
||||
const proxy = httpProxy.createProxyServer()
|
||||
const target = 'http://api'
|
||||
|
||||
app.prepare().then(() => {
|
||||
|
||||
createServer((req, res) => {
|
||||
const parsedUrl = parse(req.url, true)
|
||||
const { pathname } = parsedUrl
|
||||
|
||||
if (pathname.startsWith('/api/'))
|
||||
proxy.web(req, res, { target }, error => console.log('Error!', error))
|
||||
else
|
||||
handle(req, res, parsedUrl)
|
||||
|
||||
}).listen(80, err => {
|
||||
if (err) throw err
|
||||
console.log('> Frontend Ready 🚀')
|
||||
})
|
||||
|
||||
})
|
Reference in New Issue
Block a user