I am working in MEAN stack project. In my project I have an admin and client module.
Here is my folder structure
- admin
- templates
- controller
- app.js
- client
- templates
- controller
- app.js
- server.js
For removing # tag from url I have added html5mode true and the following code in server.js file
app.get('/*', function (req, res, next) {
res.sendFile(path.resolve('client/index.html'));
});
app.get('/admin/*', function (req, res, next) {
res.sendFile(path.resolve('admin/index.html'));
});
Here is my server.js file
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var path = require('path');
var session = require('express-session');
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/edb');
app.all('/', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next()
});
app.use(session({secret: 'keyboard cat', cookie: { maxAge: 60000 }, resave: true, saveUninitialized: true }))
app.use('/', express.static('app', { redirect: false }));
app.get('/*', function (req, res, next) {
res.sendFile(path.resolve('client/index.html'));
});
app.get('/admin/*', function (req, res, next) {
res.sendFile(path.resolve('admin/index.html'));
});
app.get('/api/enquiry', function(req, res)
{
console.log("hai");
dbenq.find(function(err, enquiry){
if(err)
res.send(err);
res.json(enquiry);
});
});
Please help to find out the solution
Thank you
via Athi
No comments:
Post a Comment