From 49b77c5c03467688b6c6b9b60fe827cb8cd73573 Mon Sep 17 00:00:00 2001 From: Jack Foltz Date: Wed, 1 Aug 2018 11:54:35 -0400 Subject: [PATCH] Clean up routes folder --- app/routes/{ => api}/auth.js | 10 +++++----- app/routes/{invite.js => api/invites.js} | 10 +++++----- app/routes/{ => api}/keys.js | 4 ++-- app/routes/{ => api}/upload.js | 8 ++++---- app/routes/{ => api}/users.js | 2 +- app/routes/{ => api}/view.js | 4 ++-- app/routes/routes.js | 30 ++++++++++++++++++------------ 7 files changed, 37 insertions(+), 31 deletions(-) rename app/routes/{ => api}/auth.js (92%) rename app/routes/{invite.js => api/invites.js} (90%) rename app/routes/{ => api}/keys.js (96%) rename app/routes/{ => api}/upload.js (76%) rename app/routes/{ => api}/users.js (91%) rename app/routes/{ => api}/view.js (92%) diff --git a/app/routes/auth.js b/app/routes/api/auth.js similarity index 92% rename from app/routes/auth.js rename to app/routes/api/auth.js index 5d5eecc..cda9d28 100644 --- a/app/routes/auth.js +++ b/app/routes/api/auth.js @@ -2,16 +2,16 @@ const express = require('express'); const router = express.Router(); const config = require('config'); -const ModelPath = '../models/'; +const ModelPath = '../../models/'; const User = require(ModelPath + 'User.js'); const Invite = require(ModelPath + 'Invite.js'); const passport = require('passport'); -const canonicalizeRequest = require('../util/canonicalize').canonicalizeRequest; -const requireAuth = require('../util/auth').requireAuth; -const wrap = require('../util/wrap.js'); -const verifyBody = require('../util/verifyBody'); +const canonicalizeRequest = require('../../util/canonicalize').canonicalizeRequest; +const requireAuth = require('../../util/auth').requireAuth; +const wrap = require('../../util/wrap.js'); +const verifyBody = require('../../util/verifyBody'); // Wraps passport.authenticate to return a promise const authenticate = (req, res, next) => { diff --git a/app/routes/invite.js b/app/routes/api/invites.js similarity index 90% rename from app/routes/invite.js rename to app/routes/api/invites.js index 96312e1..8447824 100644 --- a/app/routes/invite.js +++ b/app/routes/api/invites.js @@ -2,14 +2,14 @@ const express = require('express'); const router = express.Router(); const crypto = require('crypto'); -const ModelPath = '../models/'; +const ModelPath = '../../models/'; const Invite = require(ModelPath + 'Invite.js'); const User = require(ModelPath + 'User.js'); -const wrap = require('../util/wrap.js'); -const requireAuth = require('../util/auth').requireAuth; -const verifyScope = require('../util/verifyScope'); -const verifyBody = require('../util/verifyBody'); +const wrap = require('../../util/wrap.js'); +const requireAuth = require('../../util/auth').requireAuth; +const verifyScope = require('../../util/verifyScope'); +const verifyBody = require('../../util/verifyBody'); const updateInviteCount = async (req, next) => diff --git a/app/routes/keys.js b/app/routes/api/keys.js similarity index 96% rename from app/routes/keys.js rename to app/routes/api/keys.js index 299a578..378af57 100644 --- a/app/routes/keys.js +++ b/app/routes/api/keys.js @@ -2,8 +2,8 @@ var express = require('express'); var router = express.Router(); var crypto = require('crypto'); -var User = require('../models/User.js'); -var Key = require('../models/Key.js'); +var User = require('../../models/User.js'); +var Key = require('../../models/Key.js'); var requireScope = function (perm) { return function(req, res, next) { diff --git a/app/routes/upload.js b/app/routes/api/upload.js similarity index 76% rename from app/routes/upload.js rename to app/routes/api/upload.js index fdaefb9..ee86b6b 100644 --- a/app/routes/upload.js +++ b/app/routes/api/upload.js @@ -2,13 +2,13 @@ const express = require('express'); const router = express.Router(); const config = require('config'); -const ModelPath = '../models/'; +const ModelPath = '../../models/'; const Upload = require(ModelPath + 'Upload.js'); -const uploadMultipart = require('../util/upload/multipart'); -const updateStats = require('../util/upload/stats'); +const uploadMultipart = require('../../util/upload/multipart'); +const updateStats = require('../../util/upload/stats'); -const wrap = require('../util/wrap.js'); +const wrap = require('../../util/wrap.js'); router.post('/', uploadMultipart, wrap(async (req, res) => { const upload = { diff --git a/app/routes/users.js b/app/routes/api/users.js similarity index 91% rename from app/routes/users.js rename to app/routes/api/users.js index c5270a6..0ba70f3 100644 --- a/app/routes/users.js +++ b/app/routes/api/users.js @@ -1,7 +1,7 @@ var express = require('express'); var router = express.Router(); -var User = require('../models/User.js'); +var User = require('../../models/User.js'); var requireScope = function (perm) { return function(req, res, next) { diff --git a/app/routes/view.js b/app/routes/api/view.js similarity index 92% rename from app/routes/view.js rename to app/routes/api/view.js index 63f1cd8..4462e35 100644 --- a/app/routes/view.js +++ b/app/routes/api/view.js @@ -2,10 +2,10 @@ const express = require('express'); const router = express.Router(); const config = require('config'); -const ModelPath = '../models/'; +const ModelPath = '../../models/'; const Upload = require(ModelPath + 'Upload.js'); -const wrap = require('../util/wrap.js'); +const wrap = require('../../util/wrap.js'); const incrementViews = async id => diff --git a/app/routes/routes.js b/app/routes/routes.js index 93a67ee..fa59c1f 100644 --- a/app/routes/routes.js +++ b/app/routes/routes.js @@ -1,26 +1,32 @@ +// Views const index = require('./index.js'); const home = require('./home.js'); -const upload = require('./upload.js'); -const view = require('./view.js'); -const auth = require('./auth.js'); const register = require('./register.js'); const login = require('./login.js'); const panel = require('./panel.js'); -const keys = require('./keys.js'); -const invites = require('./invite.js'); -const users = require('./users.js'); + +// API +const auth = require('./api/auth.js'); +const upload = require('./api/upload.js'); +const view = require('./api/view.js'); +const invites = require('./api/invites.js'); +const keys = require('./api/keys.js'); +const users = require('./api/users.js'); module.exports = function (app) { app.use('/', index); app.use('/home', home); - app.use('/v', view); - app.use('/api/upload', upload); - app.use('/api/auth', auth); - app.use('/api/keys', keys); - app.use('/api/invites', invites); - app.use('/api/users', users); app.use('/register', register); app.use('/login', login); app.use('/panel', panel); app.use('/panel*', panel); + + + app.use('/api/auth', auth); + app.use('/api/upload', upload); + app.use('/v', view); + app.use('/api/view', view); + app.use('/api/invites', invites); + app.use('/api/keys', keys); + app.use('/api/users', users); }; \ No newline at end of file