Skip to content

Commit

Permalink
add server.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Sha-dos committed Feb 23, 2024
1 parent a045375 commit ec1ac1b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"typescript": "5.0.4"
},
"devDependencies": {
"@tauri-apps/cli": "^1.5.9",
"webpack": "^5.90.3"
}
}
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 { join } = require("path");
const { parse } = require("url");
const next = require("next");

const dev = process.env.NODE_ENV !== "production";
const hostname = "localhost";
const port = 3000;

const app = next({ dev, hostname, port });
const handle = app.getRequestHandler();

app.prepare().then(() => {
createServer((req, res) => {
const parsedUrl = parse(req.url, true);
const { pathname } = parsedUrl;
if (
pathname === "/sw.js" ||
/^\/(workbox|worker|fallback)-\w+\.js$/.test(pathname)
) {
const filePath = join(__dirname, ".next", pathname);
app.serveStatic(req, res, filePath);
} else {
handle(req, res, parsedUrl);
}
}).listen(port, () => {
console.log(`> Ready on http://${hostname}:${port}`);
});
});

0 comments on commit ec1ac1b

Please sign in to comment.