Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
41 lines (39 loc) · 1.39 KB
/
Copy pathapp.js
File metadata and controls
41 lines (39 loc) · 1.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
const express=require('express')
const fileUpload = require("express-fileupload");
const fileMissing=require('./middleware/noFile')
const allowedExt=require('./middleware/allowedExt')
const fileSizeLimit=require('./middleware/fileSizeLimit')
const galerieControler=require('./controler/galerieControler')
const saveDb=require('./middleware/savingDb')
const PORT=process.env.PORT||3700
const path=require('path')
const app=express()
app.use(express.static(path.join(__dirname,'/public')))
app.use(express.static(path.join(__dirname,'/files')))
app.use(express.json())
app.use(express.urlencoded({extended:false}))
app.get('/',(req,res)=>{
res.sendFile(path.join(__dirname,'Site','index.html'))
})
app.get('/galerie',(req,res)=>{
res.sendFile(path.join(__dirname,'site','galerie.html'))
})
app.post('/upload',
fileUpload({ createParentPath: true }),
fileMissing,
allowedExt(['.jpg','.jpeg','.png','.gif']),
fileSizeLimit,
saveDb,
(req,res)=>{
const profils=req.files
const profil=profils.profil
const patht=path.join(__dirname,'files',profil.name)
profil.mv(patht,(err)=>{
if(err) return res.status(500).json({status:'error',message:err})
})
res.json({status:'success','message':`the profil ${profil.name} have been saved succefully`})
})
app.get('/galeriepersonnel',galerieControler)
app.listen(PORT,()=>{
console.log(`Server is running on port ${PORT}`)
})