diff --git a/next.config.js b/next.config.js index e2155fe..2077ce0 100644 --- a/next.config.js +++ b/next.config.js @@ -14,49 +14,49 @@ module.exports = { // } - async rewrites() { - return [ - { - has: [ - { - type: 'host', - value: 'rancher.vzxy.net', - }, - ], - // source: '/:path*', - source: '/', - destination: '/k8s/clusters/c-m-6wzgb6p6/api/v1/namespaces/sammwise/services/http%3Asammwise%3A80/proxy/', - }, - { - has: [ - { - type: 'host', - value: 'rancher.vzxy.net', - }, - ], - source: '/about', - destination: '/k8s/clusters/c-m-6wzgb6p6/api/v1/namespaces/sammwise/services/http%3Asammwise%3A80/proxy/about', - }, - { - has: [ - { - type: 'host', - value: 'rancher.vzxy.net', - }, - ], - source: '/assessment', - destination: '/k8s/clusters/c-m-6wzgb6p6/api/v1/namespaces/sammwise/services/http%3Asammwise%3A80/proxy/assessment', - }, - { - has: [ - { - type: 'host', - value: 'rancher.vzxy.net', - }, - ], - source: '/assessment', - destination: '/k8s/clusters/c-m-6wzgb6p6/api/v1/namespaces/sammwise/services/http%3Asammwise%3A80/proxy/assessment', - }, - ] - } + // async rewrites() { + // return [ + // { + // has: [ + // { + // type: 'host', + // value: 'rancher.vzxy.net', + // }, + // ], + // // source: '/:path*', + // source: '/', + // destination: '/k8s/clusters/c-m-6wzgb6p6/api/v1/namespaces/sammwise/services/http%3Asammwise%3A80/proxy/', + // }, + // { + // has: [ + // { + // type: 'host', + // value: 'rancher.vzxy.net', + // }, + // ], + // source: '/about', + // destination: '/k8s/clusters/c-m-6wzgb6p6/api/v1/namespaces/sammwise/services/http%3Asammwise%3A80/proxy/about', + // }, + // { + // has: [ + // { + // type: 'host', + // value: 'rancher.vzxy.net', + // }, + // ], + // source: '/assessment', + // destination: '/k8s/clusters/c-m-6wzgb6p6/api/v1/namespaces/sammwise/services/http%3Asammwise%3A80/proxy/assessment', + // }, + // { + // has: [ + // { + // type: 'host', + // value: 'rancher.vzxy.net', + // }, + // ], + // source: '/assessment', + // destination: '/k8s/clusters/c-m-6wzgb6p6/api/v1/namespaces/sammwise/services/http%3Asammwise%3A80/proxy/assessment', + // }, + // ] + // } } diff --git a/package.json b/package.json index b4eed3b..787033a 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,9 @@ "version": "0.1.0", "private": true, "scripts": { - "dev": "next dev", + "dev": "node server.js", "build": "next build", - "start": "next start", + "start": "NODE_ENV=production node server.js", "lint": "next lint" }, "dependencies": { diff --git a/server.js b/server.js new file mode 100644 index 0000000..63d794b --- /dev/null +++ b/server.js @@ -0,0 +1,29 @@ +const { createServer } = require('http'); +const { parse } = require('url'); +const next = require('next'); + +const dev = process.env.NODE_ENV !== 'production'; +const app = next({ dev }); +const handle = app.getRequestHandler(); + +// TODO make this configurable with n hostnames to support, for n proxys +const PROXY_HOSTNAME = "rancher.vzxy.net" +const PROXY_PATHNAME = "/k8s/clusters/c-m-6wzgb6p6/api/v1/namespaces/sammwise/services/http:sammwise:80/proxy" + +app.prepare().then(() => { + createServer((req, res) => { + const parsedUrl = parse(req.url, true); + const { hostname, pathname } = parsedUrl; + // parsedUrl. + + // check configured hostnames and qualifier for non proxy paths + if (hostname === PROXY_HOSTNAME && !pathname.includes("/proxy")) { + // Handle requests to / + app.render(req, res, PROXY_PATHNAME + pathname, parsedUrl.query); + } else { + handle(req, res, parsedUrl) + } + }).listen(3000, () => { + console.log('Server started on http://localhost:3000'); + }); +}); \ No newline at end of file