@@ -37,16 +37,6 @@ const MongoStore = connectMongo(session);
3737
3838app . get ( '/health' , ( req , res ) => res . json ( { success : true } ) ) ;
3939
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-
5040const allowedCorsOrigins = [
5141 / p 5 j s \. o r g $ / ,
5242] ;
@@ -75,23 +65,6 @@ app.use(corsMiddleware);
7565// Enable pre-flight OPTIONS route for all end-points
7666app . options ( '*' , corsMiddleware ) ;
7767
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-
9568app . use ( bodyParser . urlencoded ( { limit : '50mb' , extended : true } ) ) ;
9669app . use ( bodyParser . json ( { limit : '50mb' } ) ) ;
9770app . use ( cookieParser ( ) ) ;
@@ -111,16 +84,7 @@ app.use(session({
11184 } )
11285} ) ) ;
11386
114- app . use ( passport . initialize ( ) ) ;
115- app . use ( passport . session ( ) ) ;
11687app . 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-
12488// This is a temporary way to test access via Personal Access Tokens
12589// Sending a valid username:<personal-access-token> combination will
12690// return the user's information.
@@ -129,6 +93,42 @@ app.get(
12993 passport . authenticate ( 'basic' , { session : false } ) , ( req , res ) => res . json ( req . user )
13094) ;
13195
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+
132132// this is supposed to be TEMPORARY -- until i figure out
133133// isomorphic rendering
134134app . use ( '/' , serverRoutes ) ;
0 commit comments