Last active
October 4, 2019 01:38
-
-
Save enzodanjour/a9b4620864121be61625ee5988374dff to your computer and use it in GitHub Desktop.
Codigo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const express = require("express"); | |
| const multer = require("multer"); | |
| const uploadConfig = require("./config/upload"); | |
| const SessionController = require("./controllers/SessionController"); | |
| const SpotController = require("./controllers/SpotController"); | |
| const routes = express.Router(); | |
| const upload = multer(uploadConfig); | |
| routes.post("/sessions", SessionController.store); | |
| routes.post("/spots", upload.single("thumbnail"), SpotController.store); | |
| module.exports = routes; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const express = require("express"); | |
| const mongoose = require("mongoose"); | |
| const routes = require("./routes"); | |
| const app = express(); | |
| mongoose.connect( | |
| "mongodb+srv://ademir:ademir@aircnc-j47qf.mongodb.net/aircnc?retryWrites=true&w=majority", | |
| { | |
| useNewUrlParser: true, | |
| useUnifiedTopology: true | |
| } | |
| ); | |
| // GET, POST, DELETE, PUT | |
| //req.querry = Acessar querry params (para filtros) | |
| //req.params = Acessar route params (para edição, delete) | |
| //req.body = Acessar corpo da requisição (Para criação, ediçao) | |
| app.use(express.json()); | |
| app.use(routes); | |
| app.listen(8080); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const multer = require("multer"); | |
| const path = require("path"); | |
| module.exports = { | |
| Storage: multer.diskStorage({ | |
| destination: path.resolve(__dirname, "..", "..", "uploads"), | |
| filename: (req, file, cb) => { | |
| const ext = path.extname(file.originalname); | |
| const name = path.basename(file.originalname, ext); | |
| cb(null, `${name}-${Date.now()}${ext}`); | |
| } | |
| }) | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment