Skip to content

Commit f82b2b9

Browse files
author
elias
committed
init project
0 parents  commit f82b2b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+21776
-0
lines changed

.gitignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.DS_Store
2+
node_modules
3+
/backend/node_modules
4+
/build
5+
/.svelte-kit
6+
/package
7+
.env
8+
.env.*
9+
!.env.example
10+
.vercel
11+
.output
12+
vite.config.js.timestamp-*
13+
vite.config.ts.timestamp-*

.npmrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
engine-strict=true
2+
resolution-mode=highest

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# SvelteKit + NodeJs CRUD
2+
3+
## Front-end
4+
5+
In root directory,
6+
7+
```bash
8+
npm install
9+
10+
npm run dev
11+
12+
```
13+
14+
## Back-end
15+
16+
In backend directory
17+
18+
```bash
19+
npm install
20+
21+
# or start the server and open the app in a new browser tab
22+
npm start
23+
```
24+
25+
## Before run Back-end, don't forget installing MongoDB

backend/.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
6+
# testing
7+
8+
# production
9+
10+
# misc
11+
.env.development
12+
.env.production

backend/config/mongo.conf

Whitespace-only changes.

backend/index.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const express = require("express");
2+
3+
const http = require("http");
4+
5+
const app = express();
6+
const bodyParser = require("body-parser");
7+
8+
const cors = require("cors");
9+
app.use(cors({ origin: true }));
10+
11+
const mongoose = require("mongoose");
12+
13+
require("dotenv").config();
14+
const PORT = 4000;
15+
16+
17+
app.use(bodyParser.json({ limit: "10mb", extended: true }));
18+
app.use(bodyParser.urlencoded({ limit: "10mb", extended: true }));
19+
20+
const server = http.createServer(app);
21+
22+
mongoose.connect("mongodb://127.0.0.1:27017", { useNewUrlParser: true });
23+
const connection = mongoose.connection;
24+
25+
connection.once("open", function () {
26+
console.log("MongoDB database connection established successfully");
27+
});
28+
29+
console.log("New client connected");
30+
31+
// app.use("/", require("./middleware"));
32+
app.use("/api/auth", require("./routes/register")());
33+
app.use("/api/rental", require("./routes/rental")());
34+
35+
server.listen(PORT, function () {
36+
console.log("Server is running on Port: " + PORT);
37+
});

backend/middleware.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const express = require("express");
2+
const User = require('./models/user.model');
3+
4+
module.exports = function(req,res,next) {
5+
console.log('middleware',req.url);
6+
if(req.url == "/register"){
7+
next();
8+
}else{
9+
var token = req.headers['token'];
10+
User.findOne({token:token},function(err,data){
11+
if(data == null){
12+
res.send('not access');
13+
}else{
14+
req.role = data.role
15+
next();
16+
}
17+
});
18+
}
19+
}

backend/models/rental.model.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const mongoose = require('mongoose');
2+
const Schema = mongoose.Schema;
3+
4+
let Rental = new Schema({
5+
name:{
6+
type:String
7+
},
8+
address:{
9+
type:String
10+
},
11+
image:{
12+
type:String
13+
}
14+
});
15+
16+
module.exports = mongoose.model('Rental', Rental);

backend/models/user.model.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const mongoose = require('mongoose');
2+
const Schema = mongoose.Schema;
3+
4+
let User = new Schema({
5+
firstName:{
6+
type:String
7+
},
8+
lastName:{
9+
type:String
10+
},
11+
username:{
12+
type:String
13+
},
14+
email:{
15+
type:String
16+
},
17+
password:{
18+
type:String
19+
},
20+
token:{
21+
type:String
22+
},
23+
role:{
24+
type:Number
25+
}
26+
});
27+
28+
module.exports = mongoose.model('User', User);

0 commit comments

Comments
 (0)