-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
45 lines (37 loc) · 1.07 KB
/
server.js
File metadata and controls
45 lines (37 loc) · 1.07 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
import express from "express";
import next from "next";
import session from "express-session";
import { initialize, session as _session, authenticate } from "./auth/passport"; // Adjust the path if needed
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });
const handle = app.getRequestHandler();
app.prepare().then(() => {
const server = express();
server.use(
session({
secret: "your-secret", // Please use a secure secret in production
resave: false,
saveUninitialized: false,
}),
);
server.use(initialize());
server.use(_session());
// Twitter OAuth Routes
server.get("/auth/twitter", authenticate("twitter"));
server.get(
"/auth/twitter/callback",
authenticate("twitter", { failureRedirect: "/" }),
function (req, res) {
// Successful authentication
res.redirect("/");
},
);
server.all("*", (req, res) => {
return handle(req, res);
});
const PORT = 3000;
server.listen(PORT, (err) => {
if (err) throw err;
console.log(`> Ready on http://localhost:${PORT}`);
});
});