-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
86 lines (68 loc) · 2.39 KB
/
Copy pathserver.js
File metadata and controls
86 lines (68 loc) · 2.39 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const express = require("express");
const app = express();
require("dotenv").config();
const port = process.env.PORT;
app.use(express.json());
//products
const products = require("./routesTwo/products"); //ניגשים לקובץ
app.use("/products",products); //בוחרים מה יופיע אחרי ה-פורט במקרה שלנו מדובר על מוצרים
//admins
const admins = require("./routesTwo/admins");
app.use("/admins",admins);
/*const valiDateAdmin = (req,res,next)=>{
const fs = require("fs");
const path = require("path");
const fileWithPath = path.join(__dirname,"admins.json");
const admins = JSON.parse(fs.readFileSync(fileWithPath , "utf-8"));
const username = req.query.username;
const password = req.query.password;
const isAdmin = admins.findIndex(p => p.username === username && p.password === password);
if(isAdmin === -1){
return res.status(401).send("You are not admin!");
}
next();
};/*
/*
//שיעור 6
/*const admins = require("./routes-2/admins");
app.use("/admins",admins);*/
/*//students routes
const students = require("./routes/students-routes.js")
app.use("/students", students);
//users routes
const users = require("./routes/users-routes.js");
app.use("/users", users);
//products routes
const products = require("./routes/products-routes.js");
const { get } = require("express/lib/response.js");
app.use("/products" , products); */
// שיעור 7
/*const Middleware = (req, res, next) => {
console.log(`Method:${req.method},URL${req.url},Time:${new Date() .toLocaleString()}`);
res.send(`Method:${req.method},URL${req.url},Time:${new Date() .toLocaleString()}`);
next();
};
app.use(Middleware);*/
/*const blockDelete = (req,res,next) =>{
const deleted = req.method;
if(deleted === 'DELETE'){
console.log("the api delete is close!!");
return res.status(403).send("the api delete is close!!")
}
next();
}
app.use(blockDelete);*/
/*const validateage =(req,res,next)=>{//מטפלים בלא
const age = Number(req.body.age);
if(age < 0 || age > 18){
return res.status(403).send("get some life");
}
next();
}
app.post("/users",validateage,(req,res)=>{// מטפלים בכן
res.status(200).send("you are in corrent age!");
console.log("get some joint's !!");
}); */
app.listen(port , ()=>{
console.log(`server is running on http://localhost:${port}`);
});