-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
168 lines (135 loc) · 4.4 KB
/
app.js
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
const express = require('express');
const exphbs = require('express-handlebars');
const path = require('path');
const apiRoutes = require('./routes/api');
const lovenseRouter = require('./routes/api/v2/lovense');
const app = express();
const port = process.env.PORT || 3000;
const port2 = 8082;
const baseURL = 'eserlexsiqht.sealosbja.site';
const baseURL2 = 'localhost';
// Add JSON and URL-encoded parsing middleware BEFORE routes
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// Handlebars setup
app.engine('handlebars', exphbs.engine({
defaultLayout: 'main',
layoutsDir: path.join(__dirname, 'views/layouts')
}));
app.set('view engine', 'handlebars');
// Add baseURL to all render calls
app.use((req, res, next) => {
// Determine which domain is being used
const host = req.get('host');
if (host.includes(baseURL2)) {
res.locals.baseURL = baseURL2;
res.locals.fullURL = `http://${baseURL2}:${port2}`;
} else {
res.locals.baseURL = baseURL;
res.locals.fullURL = `https://${baseURL}`;
}
next();
});
// Static files
app.use(express.static('public'));
// Routes
app.get('/', (req, res) => {
res.render('index');
});
// General
app.get('/api-introduction', (req, res) => {
res.redirect('/general/api-introduction');
});
app.get('/toy-supported-functions', (req, res) => {
res.redirect('/general/toy-supported-functions');
});
// Standard Solutions
app.get('/standard-api', (req, res) => {
res.redirect('/standard-solutions/standard-api');
});
app.get('/standard-api/mobile-remote', (req, res) => {
res.render('standard-solutions/standard-api-by-mobile-remote');
});
app.get('/standard-api/pc-remote', (req, res) => {
res.render('standard-solutions/standard-api-by-pc-remote');
});
app.get('/standard-socket', (req, res) => {
res.redirect('/standard-solutions/standard-socket');
});
app.get('/standard-js-sdk', (req, res) => {
res.redirect('/standard-solutions/standard-js-sdk');
});
app.get('/toy-events-api', (req, res) => {
res.redirect('/standard-solutions/toy-events-api');
});
app.get('/cam-extension', (req, res) => {
res.redirect('/cam-solutions/cam-extension');
});
app.get('/cam-kit-web', (req, res) => {
res.redirect('/cam-solutions/cam-kit-web');
});
app.get('/custom-cam-basic-api', (req, res) => {
res.redirect('/cam-solutions/custom-cam-basic-api');
});
app.get('/custom-cam-socket-api', (req, res) => {
res.redirect('/cam-solutions/custom-cam-socket-api');
});
app.get('/custom-cam-js-sdk', (req, res) => {
res.redirect('/cam-solutions/custom-cam-js-sdk');
});
app.get('/ios-sdk', (req, res) => {
res.redirect('/native-sdks/ios-sdk');
});
app.get('/android-sdk', (req, res) => {
res.redirect('/native-sdks/android-sdk');
});
app.get('/windows-sdk', (req, res) => {
res.redirect('/native-sdks/windows-sdk');
});
app.get('/unity-remote', (req, res) => {
res.redirect('/game-engine/unity-remote');
});
app.get('/unity-mobile', (req, res) => {
res.redirect('/game-engine/unity-mobile');
});
app.get('/unity-windows', (req, res) => {
res.redirect('/game-engine/unity-windows');
});
app.get('/unity-dongle', (req, res) => {
res.redirect('/game-engine/unity-dongle');
});
app.get('/unity-mac', (req, res) => {
res.redirect('/game-engine/unity-mac');
});
app.get('/unreal-remote', (req, res) => {
res.redirect('/game-engine/unreal-remote');
});
// Standard API routes
app.use('/standard-solutions/standard-api', apiRoutes);
app.use('/standard-solutions/standard-api-by-mobile-remote', apiRoutes);
app.use('/standard-solutions/standard-api-by-pc-remote', apiRoutes);
// Register the Lovense routes BEFORE the general API routes
app.use('/api/v2/lovense', lovenseRouter);
app.use('/', apiRoutes);
// 404 handler
app.use((req, res) => {
if (req.path.startsWith('/api/')) {
// Send JSON response for API routes
res.status(404).json({
success: false,
message: 'API endpoint not found'
});
} else {
// Send simple text for other routes
res.status(404).send('404 - Page Not Found');
}
});
// Start servers on both ports
app.listen(port, () => {
console.log(`Server running at https://${baseURL}`);
console.log(`Server listening on port ${port}`);
});
app.listen(port2, () => {
console.log(`Server running at http://${baseURL2}:${port2}`);
console.log(`Server listening on port ${port2}`);
});