@@ -37,16 +37,6 @@ const MongoStore = connectMongo(session);
37
37
38
38
app . get ( '/health' , ( req , res ) => res . json ( { success : true } ) ) ;
39
39
40
- // For basic auth, in setting up beta editor
41
- if ( process . env . BASIC_USERNAME && process . env . BASIC_PASSWORD ) {
42
- app . use ( basicAuth ( {
43
- users : {
44
- [ process . env . BASIC_USERNAME ] : process . env . BASIC_PASSWORD
45
- } ,
46
- challenge : true
47
- } ) ) ;
48
- }
49
-
50
40
const allowedCorsOrigins = [
51
41
/ p 5 j s \. o r g $ / ,
52
42
] ;
@@ -75,23 +65,6 @@ app.use(corsMiddleware);
75
65
// Enable pre-flight OPTIONS route for all end-points
76
66
app . options ( '*' , corsMiddleware ) ;
77
67
78
- // Body parser, cookie parser, sessions, serve public assets
79
- app . use (
80
- '/locales' ,
81
- Express . static (
82
- path . resolve ( __dirname , '../dist/static/locales' ) ,
83
- {
84
- // Browsers must revalidate for changes to the locale files
85
- // It doesn't actually mean "don't cache this file"
86
- // See: https://jakearchibald.com/2016/caching-best-practices/
87
- setHeaders : res => res . setHeader ( 'Cache-Control' , 'no-cache' )
88
- }
89
- )
90
- ) ;
91
- app . use ( Express . static ( path . resolve ( __dirname , '../dist/static' ) , {
92
- maxAge : process . env . STATIC_MAX_AGE || ( process . env . NODE_ENV === 'production' ? '1d' : '0' )
93
- } ) ) ;
94
-
95
68
app . use ( bodyParser . urlencoded ( { limit : '50mb' , extended : true } ) ) ;
96
69
app . use ( bodyParser . json ( { limit : '50mb' } ) ) ;
97
70
app . use ( cookieParser ( ) ) ;
@@ -111,16 +84,7 @@ app.use(session({
111
84
} )
112
85
} ) ) ;
113
86
114
- app . use ( passport . initialize ( ) ) ;
115
- app . use ( passport . session ( ) ) ;
116
87
app . use ( '/api/v1' , requestsOfTypeJSON ( ) , api ) ;
117
- app . use ( '/editor' , requestsOfTypeJSON ( ) , users ) ;
118
- app . use ( '/editor' , requestsOfTypeJSON ( ) , sessions ) ;
119
- app . use ( '/editor' , requestsOfTypeJSON ( ) , files ) ;
120
- app . use ( '/editor' , requestsOfTypeJSON ( ) , projects ) ;
121
- app . use ( '/editor' , requestsOfTypeJSON ( ) , aws ) ;
122
- app . use ( '/editor' , requestsOfTypeJSON ( ) , collections ) ;
123
-
124
88
// This is a temporary way to test access via Personal Access Tokens
125
89
// Sending a valid username:<personal-access-token> combination will
126
90
// return the user's information.
@@ -129,6 +93,42 @@ app.get(
129
93
passport . authenticate ( 'basic' , { session : false } ) , ( req , res ) => res . json ( req . user )
130
94
) ;
131
95
96
+ // For basic auth, but can't have double basic auth for API
97
+ if ( process . env . BASIC_USERNAME && process . env . BASIC_PASSWORD ) {
98
+ app . use ( basicAuth ( {
99
+ users : {
100
+ [ process . env . BASIC_USERNAME ] : process . env . BASIC_PASSWORD
101
+ } ,
102
+ challenge : true
103
+ } ) ) ;
104
+ }
105
+
106
+ // Body parser, cookie parser, sessions, serve public assets
107
+ app . use (
108
+ '/locales' ,
109
+ Express . static (
110
+ path . resolve ( __dirname , '../dist/static/locales' ) ,
111
+ {
112
+ // Browsers must revalidate for changes to the locale files
113
+ // It doesn't actually mean "don't cache this file"
114
+ // See: https://jakearchibald.com/2016/caching-best-practices/
115
+ setHeaders : res => res . setHeader ( 'Cache-Control' , 'no-cache' )
116
+ }
117
+ )
118
+ ) ;
119
+ app . use ( Express . static ( path . resolve ( __dirname , '../dist/static' ) , {
120
+ maxAge : process . env . STATIC_MAX_AGE || ( process . env . NODE_ENV === 'production' ? '1d' : '0' )
121
+ } ) ) ;
122
+
123
+ app . use ( passport . initialize ( ) ) ;
124
+ app . use ( passport . session ( ) ) ;
125
+ app . use ( '/editor' , requestsOfTypeJSON ( ) , users ) ;
126
+ app . use ( '/editor' , requestsOfTypeJSON ( ) , sessions ) ;
127
+ app . use ( '/editor' , requestsOfTypeJSON ( ) , files ) ;
128
+ app . use ( '/editor' , requestsOfTypeJSON ( ) , projects ) ;
129
+ app . use ( '/editor' , requestsOfTypeJSON ( ) , aws ) ;
130
+ app . use ( '/editor' , requestsOfTypeJSON ( ) , collections ) ;
131
+
132
132
// this is supposed to be TEMPORARY -- until i figure out
133
133
// isomorphic rendering
134
134
app . use ( '/' , serverRoutes ) ;
0 commit comments