Skip to content

Commit

Permalink
Add custom server with proxy for Grill
Browse files Browse the repository at this point in the history
  • Loading branch information
olehmell committed Feb 14, 2024
1 parent 30e8b92 commit ae7fcd6
Show file tree
Hide file tree
Showing 4 changed files with 329 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ WORKDIR /opt/subsocial/app

COPY --from=builder /opt/subsocial/app .

CMD [ "node_modules/.bin/next", "start", "-p", "3003" ]
CMD [ "node", "server.js" ]
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
"cy:test:video": "npm-run-all --parallel start cy:run:video",
"cy:run": "export CYPRESS_VIDEO=false && cypress run",
"cy:run:video": "cypress run",
"dev": "NODE_OPTIONS=--max_old_space_size=4096 next -p 3003",
"dev": "NODE_OPTIONS=--max_old_space_size=4096 node server.js",
"analyze": "ANALYZE=true next build",
"build": "next build",
"export": "next export",
"start": "NODE_ENV=production next start -p 3003",
"start": "NODE_ENV=production node server.js",
"graphql:types": "./scripts/graphql-generate-types.sh",
"prepare": "husky install",
"format": "prettier --write src"
Expand Down Expand Up @@ -120,6 +120,7 @@
"dayjs": "^1.9.6",
"dotenv-webpack": "^1.0.2",
"easymde": "^2.15.0",
"express": "^4.18.2",
"graphql": "^15.5.0",
"graphql-request": "^5.2.0",
"graphql-tag": "^2.11.0",
Expand Down
30 changes: 30 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const express = require('express');
const next = require('next');

const port = parseInt(process.env.PORT) || 3003;
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();

app.prepare().then(() => {
const server = express();

server.use((req, res, next) => {
const host = req.headers.host;

if (host === 'grill.so') {
return res.redirect(301, `http://grill.so/b${req.url}`);
}

next();
});

server.all('*', (req, res) => {
return handle(req, res);
});

server.listen(port, (err) => {
if (err) throw err;
console.log(`> Ready on http://localhost:${port}`);
});
});
Loading

0 comments on commit ae7fcd6

Please sign in to comment.