-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (30 loc) · 947 Bytes
/
Copy pathindex.js
File metadata and controls
39 lines (30 loc) · 947 Bytes
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
const express = require('express')
const app = express()
const path = require('path')
const multer = require('multer')
const bodyParser = require('body-parser')
const router = require('./routes.js')
app.set('view engine', 'ejs')
app.set('views', 'views')
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, 'public/images')
},
filename: (req, file, cb) => {
cb(null, 'post_' + file.originalname)
}
})
app.use(multer({storage: storage}).single('image'))
app.use('/images', express.static(path.join(__dirname, 'images')))
app.use(express.static(path.join(__dirname, 'public')))
app.use(bodyParser.urlencoded({ extended: false }))
const connection = require('./config/connection.js')
app.use(router)
app.use((req, res) => {
res.status(404).render('not-found', {title: 'Erro! - Techblog'})
})
connection.sync().then(result => {
app.listen(3333)
}).catch(error => {
console.log(error)
})