Skip to content

Commit

Permalink
try a custom server
Browse files Browse the repository at this point in the history
  • Loading branch information
Saturn-V committed Mar 6, 2024
1 parent b8f081c commit bc1c3f3
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 47 deletions.
90 changes: 45 additions & 45 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
// },
// ]
// }
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
29 changes: 29 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -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');
});
});

0 comments on commit bc1c3f3

Please sign in to comment.