Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F4498687
server_routes.cjs
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
927 B
Referenced Files
None
Subscribers
None
server_routes.cjs
View Options
// Example HTTP server with basic routing
function handleRequest(req, res) {
Ant.println("Request:", req.method, req.uri);
// Simple routing based on URI
if (req.uri === "/") {
return {
status: 200,
body: "Welcome to Ant HTTP Server!\n\nAvailable routes:\n GET /\n GET /hello\n GET /status\n GET /echo"
};
}
if (req.uri === "/hello") {
return {
status: 200,
body: "Hello, World!"
};
}
if (req.uri === "/status") {
return {
status: 200,
body: "Server is running!"
};
}
if (req.uri === "/echo") {
return {
status: 200,
body: "Method: " + req.method + "\nURI: " + req.uri + "\nQuery: " + req.query + "\nBody: " + req.body
};
}
// 404 for unknown routes
return {
status: 404,
body: "Not Found: " + req.uri
};
}
Ant.println("Starting HTTP server on port 8000...");
Ant.serve(8000, handleRequest);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, May 3, 7:45 AM (1 d, 3 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
523675
Default Alt Text
server_routes.cjs (927 B)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment