@@ -212,29 +212,12 @@ func (c *AppsDeleteCmd) Run() (err error) {
212212 return err
213213}
214214
215- // AppsInitCmd creates and validates server.conf and package.json to prepare an app for deployment
215+ // AppsInitCmd creates and validates package.json to prepare an app for deployment
216216type AppsInitCmd struct {
217217 StackName string `optional default:"nodejs-basic" short:"s" help:"Name of stack to deploy. Default is nodejs-basic"`
218218 Force bool `optional short:"f" help:"Resets deployment specific files to their default configuration"`
219219}
220220
221- func (c * AppsInitCmd ) buildServerConf () []byte {
222- return []byte (
223- `location / {
224- proxy_set_header X-Forwarded-For $http_x_forwarded_for;
225- proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
226- proxy_set_header Host $host;
227- include /etc/nginx/section.module/node.conf;
228- }
229-
230- location ~ "/next-proxy-hop/" {
231- proxy_set_header X-Forwarded-For $http_x_forwarded_for;
232- proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
233- proxy_set_header Host $host;
234- proxy_pass http://next-hop;
235- }` )
236- }
237-
238221// Run executes the command
239222func (c * AppsInitCmd ) Run () (err error ) {
240223 var stdout bytes.Buffer
@@ -263,27 +246,27 @@ func (c *AppsInitCmd) CreatePkgJSON(stdout, stderr bytes.Buffer) (err error) {
263246// InitializeNodeBasicApp initializes a basic node app.
264247func (c * AppsInitCmd ) InitializeNodeBasicApp (stdout , stderr bytes.Buffer ) (err error ) {
265248 if c .Force {
266- log .Println ("[INFO] Removing old versions of server.conf and package.json" )
267- err1 := os .Remove ("package.json" )
268- err2 := os .Remove ("server.conf" )
269- if err1 != nil || err2 != nil {
270- log .Println ("[ERROR] unable to remove files, perhaps they do not exist?" )
249+ log .Println ("[INFO] Removing old version of package.json" )
250+ err = os .Remove ("package.json" )
251+ if err != nil {
252+ if ! os .IsNotExist (err ) {
253+ log .Println ("[ERROR] unable to remove package.json file" )
254+ return err
255+ }
271256 } else {
272257 log .Println ("[DEBUG] Files successfully removed" )
273258 }
274259 }
275260 log .Println ("[DEBUG] Checking to see if server.conf exists" )
276261 checkServConf , err := os .Open ("server.conf" )
277262 if err != nil {
278- log .Println ("[WARN] server.conf does not exist. Creating server.conf" )
279- f , err := os .Create ("server.conf" )
280- if err != nil {
281- return fmt .Errorf ("error in creating a file: server.conf %w" , err )
263+ if ! os .IsNotExist (err ) {
264+ log .Println ("[ERROR] server.conf file could not be opened" )
265+ return err
282266 }
283- b := c .buildServerConf ()
284- f .Write (b )
285- defer f .Close ()
286- } else {
267+ }
268+ defer checkServConf .Close ()
269+ if err == nil {
287270 log .Println ("[INFO] Validating server.conf" )
288271 fileinfo , err := checkServConf .Stat ()
289272 if err != nil {
@@ -299,7 +282,6 @@ func (c *AppsInitCmd) InitializeNodeBasicApp(stdout, stderr bytes.Buffer) (err e
299282 log .Println ("[WARN] default location unspecified. Edit or delete server.conf and rerun this command" )
300283 }
301284 }
302- defer checkServConf .Close ()
303285 log .Println ("[DEBUG] Checking to see if package.json exists" )
304286 checkPkgJSON , err := os .Open ("package.json" )
305287 if err != nil {
0 commit comments