angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Should "ng serve" be able to serve static html files?

Open derobiom opened this issue 9 years ago • 9 comments

I have a app that runs just fine with "ng serve". BUT if I try to retrieve another (static) html file that is in my src directory, I get a 304 and it just serves up the angular app again. The only way that I can see that static html file is to change the app->index value in the .angular-cli.json file. But then my angular 2 app does not run. Is "ng serve" only meant for SPA so that it CANNOT serve up separate static html files? I wanted to have some exterior (not logged in) pages with a very different look than my "app". Just trying to find the least painful way, if there is one.

derobiom avatar Feb 27 '17 01:02 derobiom

Any extra files you want to include in the build/serve should be added to the assets property in .angular-cli.json.

Meligy avatar Feb 27 '17 02:02 Meligy

Thank you! works great now!

derobiom avatar Feb 27 '17 03:02 derobiom

  1. ng-build with your index.html set properly with its components. (or conditional app-components)
  2. rename and copy the rendered to (for example) /src/search.html
  3. in angular.json (angular-cli.json for pre v5) find "assets":
"assets": [
"src/favicon.ico",
"src/search.html",
"src/assets"
],

browse localhost:4200/search.html enjoy :)

source

bresleveloper avatar Jul 06 '18 14:07 bresleveloper

... aaaaand restart "ng serve" so the change takes effect. :)

RonNewcomb avatar Nov 02 '18 17:11 RonNewcomb

I have spent literally hours trying this, with long directory/file names, restarting constantly and still nothing appears for my http request either in the browser or by using HttpClient.

http://localhost:4203/badge1.html

Not sure what it could be. I am using the latest stuff:

Angular CLI: 7.0.7 Node: 8.11.4 OS: win32 x64 Angular: 7.0.4 ... animations, common, compiler, compiler-cli, core, forms ... http, language-service, platform-browser ... platform-browser-dynamic, router

Package Version

@angular-devkit/architect 0.10.7 @angular-devkit/build-angular 0.10.7 @angular-devkit/build-ng-packagr 0.10.7 @angular-devkit/build-optimizer 0.10.7 @angular-devkit/build-webpack 0.10.7 @angular-devkit/core 7.0.7 @angular-devkit/schematics 7.0.7 @angular/cdk 6.4.7 @angular/cli 7.0.7 @angular/material 6.4.7 @ngtools/json-schema 1.1.0 @ngtools/webpack 7.0.7 @schematics/angular 7.0.7 @schematics/update 0.10.7 ng-packagr 4.4.5 rxjs 6.3.3 typescript 3.1.6 webpack 4.19.1

stevefiedler avatar Dec 26 '18 21:12 stevefiedler

did you put it in "assets" in the angular json?

bresleveloper avatar Dec 26 '18 22:12 bresleveloper

I did, but actually it seems I inadvertently was not setting it up correctly. Even though my target asset is down the directory structure a bit, I was able to access it finally.

angualr.json:

        "assets": [
          "src/favicon.ico",
          "src/assets",
          "src"
        ],

Reference - finally got a '200' - yay!

http://localhost:4203/app/sample/examples/elements/badge-example/badge1.html

Thanks for making me re-look at it.

stevefiedler avatar Dec 27 '18 15:12 stevefiedler

I did, but actually it seems I inadvertently was not setting it up correctly. Even though my target asset is down the directory structure a bit, I was able to access it finally.

angualr.json:

        "assets": [
          "src/favicon.ico",
          "src/assets",
          "src"
        ],

Reference - finally got a '200' - yay!

http://localhost:4203/app/sample/examples/elements/badge-example/badge1.html

Thanks for making me re-look at it.

well, now we all learned something new

bresleveloper avatar Dec 27 '18 16:12 bresleveloper

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.