@@ -37,23 +37,6 @@ app.head("/", (request, response) => {
3737 response . status ( 200 ) ;
3838} ) ;
3939
40- app . use ( function ( req , res , next ) {
41- if ( ! process . env . NODE_NSFW_KEY ) {
42- next ( ) ;
43- } else if ( ! req . headers . authorization && ! ! process . env . NODE_NSFW_KEY ) {
44- //console.log("No auth");
45- return res . status ( 401 ) . json ( {
46- error : "No Authorization Provided"
47- } ) ;
48- } else if ( req . headers . authorization !== process . env . NODE_NSFW_KEY ) {
49- //console.log("invalid auth");
50- return res . status ( 401 ) . json ( {
51- error : "Invalid Authorization"
52- } ) ;
53- } else {
54- next ( ) ;
55- }
56- } ) ;
5740
5841app . use ( helmet ( ) ) ;
5942app . use ( compression ( ) ) ;
@@ -108,12 +91,6 @@ app.use(
10891app . use ( cookieParser ( ) ) ;
10992/* End Cookie Settings */
11093
111- /* Start of Routing Modules */
112- const v3_router = require ( "./routes/v3_route" ) ;
113- v3_router ( app ) ;
114-
115- /* End of Routing Modules */
116-
11794
11895const apiVersion = process . env . API_VERSION || "v3" ;
11996const testURL = "/api/" + apiVersion + "/health" ;
@@ -128,6 +105,32 @@ let docs = require(docsFolder + 'docs.json');
128105app . use ( "/docs" , swaggerUi . serve , swaggerUi . setup ( docs , {
129106 explorer : true ,
130107} ) ) ;
108+ /* Begin Authorization */
109+ app . use ( function ( req , res , next ) {
110+ if ( ! process . env . NODE_NSFW_KEY ) {
111+ next ( ) ;
112+ } else if ( ! req . headers . authorization && ! ! process . env . NODE_NSFW_KEY ) {
113+ //console.log("No auth");
114+ return res . status ( 401 ) . json ( {
115+ error : "No Authorization Provided"
116+ } ) ;
117+ } else if ( req . headers . authorization !== process . env . NODE_NSFW_KEY ) {
118+ //console.log("invalid auth");
119+ return res . status ( 401 ) . json ( {
120+ error : "Invalid Authorization"
121+ } ) ;
122+ } else {
123+ next ( ) ;
124+ }
125+ } ) ;
126+ /* End Authorization */
127+ /* Start of Routing Modules */
128+ const v3_router = require ( "./routes/v3_route" ) ;
129+ v3_router ( app ) ;
130+
131+ /* End of Routing Modules */
132+
133+
131134app . get ( "*" , function ( req , res ) {
132135 res . status ( 404 ) ;
133136
0 commit comments