@@ -92,6 +92,13 @@ function initSettings (args) {
9292 var name = files [ i ] . replace ( path . extname ( files [ i ] ) , '' )
9393 langs [ name ] = require ( path . join ( dpath , files [ i ] ) )
9494 }
95+ if ( args . config . admin . locale ) {
96+ var fpath = args . config . admin . locale
97+ var fname = path . basename ( fpath )
98+ var locale = fname . replace ( path . extname ( fname ) , '' )
99+ langs [ locale ] = require ( fpath )
100+ args . locale = locale
101+ }
95102 return langs
96103 } ) ( )
97104
@@ -131,18 +138,21 @@ function initSettings (args) {
131138 var root = args . config . admin . root
132139 if ( / .* \/ $ / . test ( root ) ) args . config . admin . root = root . slice ( 0 , - 1 )
133140 }
134- else {
141+ else {
135142 args . config . admin . root = ''
136143 }
137144
138- // layouts/themes/languages
145+ // layouts
139146 args . layouts = args . config . admin . layouts !== undefined
140147 ? args . config . admin . layouts
141148 : true
149+
150+ // themes
142151 args . themes = args . config . admin . themes === undefined || args . config . admin . themes
143152 ? { theme : require ( path . join ( __dirname , 'config/themes' ) ) }
144153 : null
145154
155+ // languages
146156 args . languages = ( ( ) => {
147157 if ( args . config . admin . languages !== undefined && ! args . config . admin . languages ) return null
148158 var langs = [ ]
@@ -152,6 +162,12 @@ else {
152162 return { language : langs }
153163 } ) ( )
154164
165+ // footer
166+ args . footer = args . config . admin . footer || {
167+ text : 'Express Admin' ,
168+ url : 'https://github.com/simov/express-admin'
169+ }
170+
155171 // static
156172 args . libs = dcopy ( require ( path . join ( __dirname , 'config/libs' ) ) )
157173 args . libs . external = { css : [ ] , js : [ ] }
@@ -178,29 +194,34 @@ function initServer (args) {
178194 . set ( 'view engine' , 'html' )
179195 . engine ( 'html' , consolidate . hogan )
180196
181- // .use(bodyParser.json())
197+ . use ( bodyParser . json ( ) )
182198 . use ( bodyParser . urlencoded ( { extended : true } ) )
183199 . use ( multipart ( ) )
184200
185201 . use ( cookieParser ( ) )
186- . use ( args . session || session ( {
202+ . use ( session ( args . config . admin . session || {
187203 name : 'express-admin' ,
188- secret : 'very secret - required ' ,
204+ secret : 'very secret' ,
189205 saveUninitialized : true ,
190206 resave : true
191207 } ) )
192208 . use ( r . auth . status ) // session middleware
193209 . use ( csrf ( ) )
194-
195210 . use ( methodOverride ( ) )
196- . use ( serveStatic ( path . join ( __dirname , 'public' ) ) )
197- . use ( serveStatic ( ( ( ) => {
198- var dpath = path . resolve ( __dirname , 'node_modules/express-admin-static' )
199- if ( ! fs . existsSync ( dpath ) ) {
200- dpath = path . resolve ( __dirname , '../express-admin-static' )
201- }
202- return dpath
203- } ) ( ) ) )
211+
212+ // custom favicon
213+ if ( args . config . admin . favicon ) {
214+ app . use ( serveStatic ( args . config . admin . favicon ) )
215+ }
216+
217+ app . use ( serveStatic ( path . join ( __dirname , 'public' ) ) )
218+ app . use ( serveStatic ( ( ( ) => {
219+ var dpath = path . resolve ( __dirname , 'node_modules/express-admin-static' )
220+ if ( ! fs . existsSync ( dpath ) ) {
221+ dpath = path . resolve ( __dirname , '../express-admin-static' )
222+ }
223+ return dpath
224+ } ) ( ) ) )
204225
205226 if ( ! args . readonly ) app . set ( 'view cache' , true )
206227
@@ -218,9 +239,9 @@ function initServer (args) {
218239 res . locals . _admin = args
219240
220241 // i18n
221- var lang = req . cookies . lang || 'en'
242+ var lang = req . cookies . lang || args . locale || 'en'
222243 res . cookie ( 'lang' , lang , { path : '/' , maxAge : 900000000 } )
223- moment . locale ( lang == 'cn' ? 'zh-cn' : lang )
244+ moment . locale ( lang === 'cn' ? 'zh-cn' : lang )
224245
225246 // template vars
226247 res . locals . string = args . langs [ lang ]
@@ -229,6 +250,7 @@ function initServer (args) {
229250 res . locals . themes = args . themes
230251 res . locals . layouts = args . layouts
231252 res . locals . languages = args . languages
253+ res . locals . footer = args . footer
232254
233255 // required for custom views
234256 res . locals . _admin . views = app . get ( 'views' )
@@ -278,6 +300,10 @@ function initServer (args) {
278300}
279301
280302function init ( config , done ) {
303+ if ( ! config . config ) throw new Error ( 'Admin `config` is required!' )
304+ if ( ! config . settings ) config . settings = { }
305+ if ( ! config . users ) config . users = { }
306+ if ( ! config . custom ) config . custom = { }
281307 initDatabase ( config , ( err ) => {
282308 if ( err ) return done ( err )
283309 initSettings ( config )
0 commit comments