Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
PowerPanel-Backend/app.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
61 lines (41 sloc)
1.34 KB
This file contains 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 logger = require('morgan'); | |
const bodyParser = require('body-parser'); | |
const jwt = require('express-jwt'); | |
const cors = require('cors'); | |
const path = require('path'); | |
const app = express(); | |
const config = require('./config'); | |
app.use(logger('dev')); | |
app.use(cors()); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ extended: false })); | |
app.get('/', function(req, res){ | |
res.status(200).send({ message:"PowerPanel API v1" }); | |
}); | |
const auth = require('./routes/auth.routes'); | |
const user = require('./routes/user.routes'); | |
const admin = require('./routes/admin.routes'); | |
const generator = require('./routes/generator.routes'); | |
const org = require('./routes/org.routes'); | |
const data = require('./routes/data.routes'); | |
app.use('/auth', auth); | |
app.use(jwt({ | |
secret: config.jwt_public, | |
credentialsRequired: true | |
})); | |
app.use(function (err, req, res, next) { | |
if (err.name === 'UnauthorizedError') { | |
res.status(401).send({ message: "Unauthorized" }); | |
} | |
}); | |
app.use('/user', user); | |
app.use('/admin', admin); | |
app.use('/generator', generator); | |
app.use('/org', org); | |
app.use('/data', data); | |
app.use(function(req, res, next){ | |
res.status(404).send({message: "Unknown Endpoint"}); | |
}); | |
app.listen(config.port, () => console.log(`Listening on port ${config.port}`)) | |
module.exports = app; |