@@ -46,19 +46,28 @@ async function getAssets(folder) {
4646 } ) ;
4747
4848 const indexHTML = assets . find ( asset => asset . name . includes ( 'index.html' ) ) ;
49+ const authHandlerFn = fs . readFileSync ( path . join ( __dirname , './serverless/assets/verify_passcode.js' ) ) ;
4950
50- assets . push ( {
51- ...indexHTML ,
52- path : '/' ,
53- name : '/' ,
54- } ) ;
55- assets . push ( {
56- ...indexHTML ,
57- path : '/login' ,
58- name : '/login' ,
59- } ) ;
51+ const allAssets = assets . concat ( [
52+ {
53+ ...indexHTML ,
54+ path : '/' ,
55+ name : '/' ,
56+ } ,
57+ {
58+ ...indexHTML ,
59+ path : '/login' ,
60+ name : '/login' ,
61+ } ,
62+ {
63+ name : 'auth-handler' ,
64+ path : '/auth-handler.js' ,
65+ content : authHandlerFn ,
66+ access : 'private' ,
67+ } ,
68+ ] ) ;
6069
61- return assets ;
70+ return allAssets ;
6271}
6372
6473async function findApp ( ) {
@@ -80,7 +89,7 @@ async function getAppInfo() {
8089 const assets = await appInstance . assets . list ( ) ;
8190
8291 const functions = await appInstance . functions . list ( ) ;
83- const tokenServerFunction = functions . find ( fn => fn . friendlyName === 'token' ) ;
92+ const tokenServerFunction = functions . find ( fn => fn . friendlyName . includes ( 'token' ) ) ;
8493
8594 const passcodeVar = variables . find ( v => v . key === 'API_PASSCODE' ) ;
8695 const expiryVar = variables . find ( v => v . key === 'API_PASSCODE_EXPIRY' ) ;
@@ -130,6 +139,10 @@ async function displayAppInfo() {
130139
131140async function deploy ( ) {
132141 const assets = this . flags [ 'app-directory' ] ? await getAssets ( this . flags [ 'app-directory' ] ) : [ ] ;
142+ const { functions } = await getListOfFunctionsAndAssets ( __dirname , {
143+ functionsFolderNames : [ 'serverless/functions' ] ,
144+ assetsFolderNames : [ ] ,
145+ } ) ;
133146
134147 if ( this . twilioClient . username === this . twilioClient . accountSid ) {
135148 // When twilioClient.username equals twilioClient.accountSid, it means that the user
@@ -158,8 +171,6 @@ TWILIO_API_SECRET = the secret for the API Key`);
158171 const pin = getRandomInt ( 6 ) ;
159172 const expiryTime = Date . now ( ) + EXPIRY_PERIOD ;
160173
161- const fn = fs . readFileSync ( path . join ( __dirname , './video-token-server.js' ) ) ;
162-
163174 cli . action . start ( 'deploying app' ) ;
164175
165176 const deployOptions = {
@@ -170,17 +181,14 @@ TWILIO_API_SECRET = the secret for the API Key`);
170181 API_PASSCODE_EXPIRY : expiryTime ,
171182 ROOM_TYPE : this . flags [ 'room-type' ] ,
172183 } ,
173- pkgJson : { } ,
174- functionsEnv : 'dev' ,
175- functions : [
176- {
177- name : 'token' ,
178- path : '/token' ,
179- content : fn ,
180- access : 'public' ,
184+ pkgJson : {
185+ dependencies : {
186+ twilio : '^3.51.0' ,
181187 } ,
182- ] ,
183- assets : assets ,
188+ } ,
189+ functionsEnv : 'dev' ,
190+ functions,
191+ assets,
184192 } ;
185193
186194 if ( this . appInfo && this . appInfo . sid ) {
0 commit comments