Thursday 21 March 2019

Saco - pre configured express.static

short versionStop hosting static webpages with development servers and with non-production settings.Use this instead: https://github.com/bertolo1988/sacoSorry for chilling my own project but i think it is quite useful. I have been using it for 2 years.long version, for those who are learningImagine you have a react project and you want to deploy it. You will produce a folder with static content ready to be hosted. What tool should you use to host it? Nginx? Aren't you done with Chinese Gov backdoors geez... Use Node.js instead!Imagine your static content is inside /build, this would be your runServer.js:const path = require("path"); const Saco = require("saco"); new Saco.Server({ name: "my-crazy-front-end-project", rootPath: path.join(__dirname, "/build"), ip: "0.0.0.0", // not needed unless you intend to run this inside a docker container port: 4200 }).start(); Run node runServer.jsand voilá. It's running, but you won't see nothing unless you set DEBUG=saco:* node runServer.js.I heard you like Docker...The container code for most front end projects should be something like:FROM node:8-jessie # Create app directory RUN mkdir -p /usr/src/my-crazy-front-end-project WORKDIR /usr/src/my-crazy-front-end-project // copy everything else inside the container COPY . /usr/src/my-crazy-front-end-project RUN npm install EXPOSE 4200 # Start the app using npm run start (`DEBUG=saco:* node runServer.js`) CMD [ "npm", "run", "start" ] Build it:docker build -t my-crazy-front-end-project:1.0.0 .Run it:docker run -p 4200:4200 -d my-crazy-front-end-project:1.0.0

Submitted March 21, 2019 at 11:32PM by yarauuta

No comments:

Post a Comment