ninja-server
TypeScript icon, indicating that this package has built-in type declarations

0.0.12 • Public • Published
��# o v e r v i e w a p o w e r f u l s e r v e r f o r d e v e l o p i n g a n d d e p l o y i n g w e b s i t e s w i t h t h i s t o o l y o u c a n e a s i l y w r i t e a p i a n d w e b s i t e s p a g e o n f l y O n e o f t h e s t a n d o u t f e a t u r e s i s t h e a u t o m a t i c g e n e r a t i o n o f t h e s e r v e r A P I f r o m f u n c t i o n s i n t h e " a p i " f o l d e r . T h i s c a n h e l p s p e e d u p d e v e l o p m e n t b y r e d u c i n g t h e a m o u n t o f b o i l e r p l a t e c o d e n e e d e d t o s e t u p t h e s e r v e r A P I . A d d i t i o n a l l y , t h e g e n e r a t i o n o f t h e c o r r e s p o n d i n g " c l i e n t A p i " f o l d e r c a n s i m p l i f y t h e p r o c e s s o f c a l l i n g t h e s e r v e r A P I f r o m t h e f r o n t - e n d w i t h o u t h a v i n g t o w o r r y a b o u t U R L s t r u c t u r e s . I t a l s o i n t e g r a t e w i t h T y p e S c r i p t a u s e f u l f e a t u r e , a s i t p r o v i d e s t y p e c h e c k i n g a n d i m p r o v e s t h e o v e r a l l m a i n t a i n a b i l i t y o f t h e c o d e . F i n a l l y , t h e p r e s e n c e o f a p u b l i c f o l d e r f o r s t a t i c r e s o u r c e s a n d f r o n t - e n d c o d e m a k e s i t e a s y t o o r g a n i z e a n d s e r v e s t a t i c c o n t e n t . # f e a t u r e s a t g l a n c e g e n e r a t e a p i f r o m ` a p i ` f o l d e r g e n e r a t e c l i e n t A p i b a s e o f ` a p i ` f o l d e r t o u s e i n c l i e n t i f ` a p i ` w e r e i n t y p e s c r i p t t h e c l i e n t A p i w i l l b e t o o a n d h o l d t h e i r t y p e s a n d r e t u r n s o y o u c a n s i m p l y c a l l t h e m i n c l i e n t w i t h o u t w o r r y i n g a b o u t t h e u r l a n d r e t u r n t y p e a n d o t h e r s t u f f s g e n e r a t e w e b p a g e s f r o m p u b l i c f o l d e r ( c a n b e c o n f i g u r e d ) c a n w a t c h f o r f i l e c h a n g e s t o r e l o a d s u p p o r t s t y p e s c r i p t f i l e s a n d l i n k t o t h e m d i r e c t l y w i t h o u t n e e d t o c o m p i l e t h e m a n d m a k e a m e s s i n y o u r p r o j e c t s u p p o r t j s x a n d t s x s y n t a x ( i t ' s s l i g h t l y d i f f e r e n t f r o m s t a n d a r d j s x ) e x t e n d a b l e b y l e v e r a g i n g p l u g i n s # f o l d e r s t r u c t u r e a p i c l i e n t a p i p u b l i c ( a u t o m a t i c a l l y w i l l g e n e r a t e i t ) s e r v e r . c o n f i g . j s ( a u t o m a t i c a l l y w i l l g e n e r a t e i t ) # a p i f o l d e r ` n i n j a s e r v e r ` w i l l r e a d t h r o u g h a l l a p i d i r e c t o r y a n d c r e a t e u r l s a t t h e d i r e c t o r y s t r u c t u r e a n d ` r e q u i r e ` t h e t s o r j s f i l e s i t e x p e c t s t h e e x p o r t s i n t h e s e f i l e s t o b e w h e t h e r a f u n c t i o n o r a n o b j e c t t h e n i t w i l l g e n e r a t e u r l s d e p e n d s o n t h e n a m e s o f t h e s e e x p o r t s f o r e x a m p l e i f a p i h a s a f i l e n a m e d u s e r s . j s a n d i t e x p o r t s l o g i n f u n c t i o n i t w i l l g e n e r a t e a p a t h l i k e ` / u s e r s / l o g i n ` e a c h o f t h e s e f u n c t i o n c a n g e t 2 p a r a m e t e r s t h e 1 s t i s a n o b j e c t w h i c h i s p a s s e d b y t h e r e q u e s t a n d t h e o t h e r i s X C o n i f a n e x p o r t i s a n o b j e c t t h e n i t d e s t r u c t u r e i t f u r t h e r a n d c r e a t e u r l s f r o m i t f o r e x a m p l e i f u s e r s . j s w a s ` ` ` e x p o r t c o n s t a p i = { l o g i n : ( d a t a , x ) = > { } } ` ` ` t h e g e n e r a t e d p a t h w o u l d b e ` / u s e r s / a p i / l o g i n ` s o b e c a r e f u l i n n a m i n g a p i f u n c t i o n s m u s t h a v e t h i s t y p e : ( p a r a m e t e r s ? : o b j e c t , X : X C o n ) = > o b j e c t | s t r i n g p a r a m e t e r s c a n b e a n y o b j e c t X C o n h a s 3 m e m b e r s ( { r e q u e s t , h e a d e r s , s t a t u s C o d e } ) r e t r u n s a n o b j e c t a n d i t m u s t b e J S O N v a l i d o b j e c t ( e . g . n o c i r c u l a r c a l l i n o b j e c t ) w h e n t h e o p e r a t i o n i s s u c c e e d ( s t a t u s C o d e w i t h 2 x x ) o t h e r w i s e m u s t r e t u r n a n s t r i n g e x p l a i n i n g w h a t w a s g o n e w r o n g # a p i p a r a m e t e r s t h e p a r a m e t e r s c a n b e w h e t h e r f r o m u r l q u e r y o r p o s t b o d y d e p e n d s o n m e t h o d o f r e q u e s t w i t h r e q u e s t m e t h o d o f " G E T " , " D E L E T E " i t w i l l t r y t o p a r s e t h e u r l q u e r y t h e n t o j s o n w i t h r e q u e s t m e t h o d o f " P O S T " , " P U T " i t w i l l t r y t o g e t i t f r o m r e q u e s t ' s b o d y a n d t h e n c o n v e r t i t t o j s o n t h e n p a s s i t t o a p i # c l i e n t A p i ` n i n j a s e r v e r ` w i l l a u t o m a t i c a l l y c r e a t e a p i o n c l i e n t A p i f o l d e r t o b e u s e d f o r f r o n t e n d d e v e l o p i n g c l i e n t A p i f u n c t i o n s : a s y n c ( d a t a : o b j e c t ) = > o b j e c t w h e n t h e a p i w a n t s t o r e t u r n a n e r r o r w i t h a n s t a t u s c o d e o t h e r t h a n 2 x x i t m u s t r e t u r n s a n s t r i n g a s e r r o r m e s s a g e i n t h i s c a s e t h e i n c l i e n t A p i w h e n e v e r y t h i n g i s c o r r e c t i t s i m p l y r e t u r n s " r e s p o n d . j s o n ( ) " a n d o n s t a t u s C o d e o t h e r t h a n 2 x x i t w i l l t h r o w e r r o r w i t h t h e s t r i n g r e t u r n e d i t ' s u p o n t h e p r o g r a m m e r t o h a n d l e c a t c h t h e s e e r r o r s # f o r t e s t i n g y o u n e e d t o # u s i n g j s x o r t s x ` n i n j a s e r v e r ` s u p p o r t s j s x a n d t s x s y n t a x t o g e n e r a t e w e b p a g e a t c o m p i l e ( I k n o w ) o r r u n t i m e i t e x p e c t s t o g e t a f u n c t i o n n a m e d " i n d e x " f r o m t h e s e f i l e s s o i f i t n o t e x i s t i t w i l l s k i p i t t h e r e t u r n e d i n d e x f u n c t i o n i f i t w o n ' t g e t a n y p a r a m e t e r t h e n i t a s s u m e i t s s t a t i c s o w i l l b e e x e c u t e d i t a t o n c e o t h e r w i s e i t e x e c u t e s i t e a c h t i m e a r e q u e s t t o t h a t p a g e u r l i s m a d e a n d i t s p a r a m e t e r s i s e v a l u a t e d l i k e a n a p i n o t i c e o n u s i n g t s x y o u m u s t a d d t h e f o l l o w i n g c o n f i g t o t s c o n f i g . j s o n ` ` ` { " c o m p i l e r O p t i o n s " : { " j s x " : " p r e s e r v e " } , " i n c l u d e " : [ " p u b l i c / * * / * . t s x " , ] , } ` ` ` y o u s h o u l d c h a n g e p u b l i c f o l d e r t o y o u r c o n f i g u r e d f o l d e r # # # n p m s t a r t n p m t e s t # # #

Package Sidebar

Install

npm i ninja-server

Weekly Downloads

1

Version

0.0.12

License

MIT

Unpacked Size

33.8 kB

Total Files

8

Last publish

Collaborators

  • ali_safari