mirror of
https://github.com/KevinMidboe/planetposen.git
synced 2025-10-29 17:50:32 +00:00
Server setup with mongodb.
Server handles creating and fetching products and their variations. Models are saved to mongo using mongoose. STILL PRETTY BARE BONES!
This commit is contained in:
29
server/app.js
Normal file
29
server/app.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const router = express.Router();
|
||||
const server = require('http').Server(app);
|
||||
const path = require('path');
|
||||
|
||||
const mongoose = require('mongoose');
|
||||
// const MongoStore = require('connect-mongo');
|
||||
mongoose.promise = global.Promise;
|
||||
mongoose.connect('mongodb://localhost/planetposen');
|
||||
mongoose.set('debug', true);
|
||||
|
||||
const PORT = 30010;
|
||||
|
||||
const productsController = require('./controllers/product.js');
|
||||
const variationsController = require('./controllers/variation.js');
|
||||
|
||||
app.use(express.json());
|
||||
// app.use(express.urlencoded());
|
||||
|
||||
router.get('/products', productsController.allProducts)
|
||||
router.get('/product/:id', productsController.productById)
|
||||
router.post('/product', productsController.addNewProduct)
|
||||
|
||||
router.post('/variation/:id', variationsController.addNewVariationToProduct);
|
||||
app.use('/api', router);
|
||||
|
||||
console.log(`Planetposen backend running on port: ${PORT}`)
|
||||
server.listen(PORT);
|
||||
Reference in New Issue
Block a user