Instantly share code, notes, and snippets.

Embed
What would you like to do?
var express = require("express");
var login = require('./routes/loginroutes');
var clients = require('./routes/clientroutes');
var cors = require('cors');
var bodyParser = require('body-parser');
/*
Module:multer
multer is middleware used to handle multipart form data
*/
var app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:3000/');
res.setHeader('Access-Control-Allow-Credentials', true);
res.setHeader('Access-Control-Allow-Methods', ['PATCH', 'POST', 'GET', 'DELETE', 'PUT']);
res.setHeader('Access-Control-Allow-Headers', ['Content-Type']);
res.setHeader('Access-Control-Expose-Headers', ['Content-Type']);
/* res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");*/
next();
});
app.use(cors());
var router = express.Router();
// test route
router.get('/', function(req, res) {
res.json({ message: 'welcome to our upload module apis' });
});
router.post('/register', login.register);
router.post('/login', login.login);
router.post('/ajouterclient', clients.ajouterclient);
router.post('/listeclients', clients.listeclients);
//route to handle file printing and listing
app.use('/app', router);
app.listen(4000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment