mirror of
https://github.com/open5gs/open5gs.git
synced 2026-04-28 11:29:32 +00:00
backend REST API is added for MongoDB
This commit is contained in:
parent
77b45a825d
commit
5b49df0d54
6 changed files with 130 additions and 12 deletions
|
|
@ -1,5 +1,6 @@
|
|||
process.env.DB_URI = process.env.DB_URI || 'mongodb://localhost/nextepc';
|
||||
|
||||
const co = require('co');
|
||||
const next = require('next');
|
||||
|
||||
const dev = process.env.NODE_ENV !== 'production';
|
||||
|
|
@ -23,18 +24,15 @@ const api = require('./routes');
|
|||
|
||||
const Account = require('./models/account.js');
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
const db = mongoose.connection;
|
||||
co(function* () {
|
||||
yield app.prepare();
|
||||
|
||||
if (dev) {
|
||||
mongoose.set('debug', true);
|
||||
}
|
||||
mongoose.Promise = global.Promise;
|
||||
if (dev) {
|
||||
mongoose.set('debug', true);
|
||||
}
|
||||
const db = yield mongoose.connect(process.env.DB_URI)
|
||||
|
||||
mongoose.connect(process.env.DB_URI)
|
||||
.then(() => {
|
||||
return app.prepare();
|
||||
})
|
||||
.then(() => {
|
||||
// FIXME : we need to implement landing page for inserting admin account
|
||||
Account.findByUsername('admin', true, (err, account) => {
|
||||
if (err) {
|
||||
|
|
@ -74,9 +72,16 @@ mongoose.connect(process.env.DB_URI)
|
|||
}
|
||||
}));
|
||||
|
||||
server.use((req, res, next) => {
|
||||
req.db = db;
|
||||
next();
|
||||
})
|
||||
|
||||
/*
|
||||
server.use((req, res, next) => {
|
||||
csrf(req, res, next);
|
||||
})
|
||||
*/
|
||||
|
||||
server.use(passport.initialize());
|
||||
server.use(passport.session());
|
||||
|
|
@ -100,4 +105,4 @@ mongoose.connect(process.env.DB_URI)
|
|||
console.log('> Ready on http://localhost:3000');
|
||||
});
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
.catch(error => console.error(error.stack));
|
||||
|
|
|
|||
38
webui/server/models/subscriber.js
Normal file
38
webui/server/models/subscriber.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const Subscriber = new Schema({
|
||||
imsi: { type: String, unique: true, required: true },
|
||||
|
||||
access_restriction_data: Number,
|
||||
subscriber_status: Number,
|
||||
network_access_mode: Number,
|
||||
|
||||
ue_ambr: {
|
||||
max_bandwidth_ul: Number,
|
||||
max_bandwidth_dl: Number
|
||||
},
|
||||
|
||||
pdn: [{
|
||||
apn: String,
|
||||
type: Number,
|
||||
pdn_ambr: {
|
||||
max_bandwidth_ul: Number,
|
||||
max_bandwidth_dl: Number
|
||||
},
|
||||
qci: Number,
|
||||
priority_level: Number,
|
||||
pre_emption_capability: Number,
|
||||
pre_emption_vulnerability: Number
|
||||
}],
|
||||
|
||||
security: {
|
||||
k: String,
|
||||
sqn: Number,
|
||||
rand: String,
|
||||
op: String,
|
||||
amf: String
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('Subscriber', Subscriber);
|
||||
14
webui/server/routes/db.js
Normal file
14
webui/server/routes/db.js
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
const restify = require('express-restify-mongoose')
|
||||
const options = {
|
||||
prefix: '',
|
||||
version: ''
|
||||
}
|
||||
|
||||
const Subscriber = require('../models/subscriber');
|
||||
|
||||
restify.serve(router, Subscriber, options);
|
||||
|
||||
module.exports = router;
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
const express = require('express');
|
||||
const auth = require('./auth');
|
||||
const db = require('./db')
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.use('/auth', auth);
|
||||
router.use('/db', db);
|
||||
|
||||
module.exports = router;
|
||||
Loading…
Add table
Add a link
Reference in a new issue