123456789101112131415161718192021222324 |
- var express = require("express");
- var router = express.Router();
- //首页public/index.html
- router.get("/",function(req,res){
- res.sendFile(__dirname+"/"+"index.html");
- });
- //其他页面在public/views目录下
- router.get("/welcome",function(req,res){
- return res.render("admin/welcome");
- });
- router.get("/user",function(req,res){
- var data = {code:200,message:"success"};
- return res.send(JSON.stringify(data));
- });
- router.get("/user/:id",function(req,res){
- var data = [
- {id:1,name:'xxx',age:18},
- {id:2,name:'aaa',age:20},
- {id:3,name:"bbb",age:30}
- ];
- var id = req.params.id;
- return res.end(JSON.stringify(data[id]));
- });
- module.exports = router;
|