-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
63 lines (58 loc) · 1.98 KB
/
Copy pathserver.js
File metadata and controls
63 lines (58 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// Copyright (c) 2025
// Ryan Smith <smithrm23@juniata.edu>
// Simon Ramsey <ramsesa23@juniata.edu>
// All rights reserved.
//
// This software is for internal use only. Redistribution and use in source and
// binary forms, with or without modification, are not permitted unless
// explicitly authorized by the copyright holder.
//
// This code is provided "as is," without warranty of any kind, express or implied,
// including but not limited to the warranties of merchantability, fitness for a
// particular purpose, and non-infringement. In no event shall the author or
// copyright holder be liable for any claim, damages, or other liability, whether
// in an action of contract, tort, or otherwise, arising from, out of, or in
// connection with the software or the use or other dealings in the software.
//
// -----------------------------------------------------------------------------------
// Filename: server.js
// Description: Serve the Next.js app on CPanel
// Created: 2/21/25
// -----------------------------------------------------------------------------------
//
const { createServer } = require("http")
const { parse } = require("url")
const next = require("next")
const dev = process.env.NODE_ENV !== "production"
const hostname = "localhost"
const port = process.env.PORT || 3000
const app = next({ dev, hostname, port })
const handle = app.getRequestHandler()
app.prepare().then(() => {
createServer(async (req, res) => {
try {
const parsedUrl = parse(req.url, true)
const { pathname, query } = parsedUrl
if (pathname === "/a") {
await app.render(req, res, "/a", query)
}
else if (pathname === "/b") {
await app.render(req, res, "/b", query)
}
else {
await handle(req, res, parsedUrl)
}
}
catch (err) {
console.error("Error occurred handling", req.url, err)
res.statusCode = 500
res.end("Internal server error")
}
}).listen(port, (err) => {
if (err) {
throw err
}
console.log(`> Ready on http://${hostname}:${port}`)
})
})