Why could I only request the index.htm when I had run a yarn serve at local. I could not request other file,

59 views Asked by At

I'm learning about GitLab ci. There is my pipeline code. enter image description here

There was the result. I have already ensured all the variables are right. enter image description here

There is my root directory enter image description here

I guess there must be the yarn serve default configuration

I just started the serve. There is nothing change. Maybe someone can tell me why.

stages:
    - build
    - test
    - deploy staging
    - deploy production

variables:
    APP_VERSION: $CI_PIPELINE_IID
    VERSION_PATH: version.html

build website:
    image: node:16-alpine
    stage: build
    script:
        - yarn install
        - yarn lint
        - yarn test
        - yarn build
        - echo $APP_VERSION > build/version.html
    artifacts:
        paths:
            - build

test index:
    image: node:16-alpine
    stage: test
    script:
        - yarn global add serve
        - apk add curl
        - serve -s build &
        - sleep 10
        - curl http://localhost:3000 | grep 'React App'
#        - curl http://localhost:3000/$VERSION_PATH | grep $APP_VERSION
1

There are 1 answers

1
Yanjan. Kaf. On

It has nothing to do with GitLab CI configuration, you are doing everything as should be you have clearly defined the stages, the problem however is you are using

serve -s build

the -s option is made for serving single-page applications, that is it will always return the index.html on each request, it will not return any other page, so your version.html will not get served.

Change it from serve -s build to

serve build

as you can see when I made a request to version.html it gave me a 301 status and redirected me to /version

enter image description here

however, when I run it without the -s option it returns multiple pages ( status 200)

enter image description here

so run serve without -s option