Coder Social home page Coder Social logo

geooot / ss-next Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 0.0 88 KB

ServiceStack and .NET 5.0 Next.js App Template

C# 40.98% Shell 0.11% TypeScript 43.55% JavaScript 15.36%
servicestack template nextjs nextjs-boilerplate typescript dotnet dotnet-core dotnet-5

ss-next's Introduction

ServiceStack .NET 5.0 Next JS Template

.NET 5.0 Next.js App Template

Browse source code and install with dotnet-new:

$ dotnet tool install -g x

$ x new geooot/ss-next <your app name>

Description

Next.js is an opinionated structured React framework for rapidly developing Web Applications.

Next also enables the development of high-performance responsive Web Apps by employing advanced packaging techniques like automatic code spliting, link prefetching, SPA navigation of statically-generated cacheable assets and integrated support for ES6/7 transpilation and js/css bundling and minification.

This was created based of the vue-next service stack template and the next typescript template.

Install Dependencies

After creating your project go to your MyApp folder and install your client App dependencies with:

$ npm install

If your IDE doesn't automatically install your .NET NuGet Dependencies, you can manually install them with:

$ dotnet restore

Important Considerations

  • Next JS API handlers will not work out of the box
  • Dynamic Routes generate the corresponding ServiceStack routes on npm run build (or really npm run generate) using the template in MyApp.ServiceInterface/MyAppRouteServices.cs.template and the generate script in MyApp/next.config.js
  • The priority in which routes are handled is up to ServiceStack's routing rules but they mostly match Next.js's routing rules
  • Optional catch all routes are supported in terms of syntax but don't really work as documented in next js.
  • Catch all routes are supported with the addition of the fact that they act like optional catch all routes if no index page is there
    • For example: /pathto/[[..slug]].tsx will accept requests from /pathto and /pathto/wherever/you/want unless there exists a /pathto/index.tsx in which /pathto goes to /pathto/index.tsx

Dev Workflow

Start a watched .NET Core build in the background from the command-line with:

$ npm run dotnet-watch

In a new terminal window start a watched next dev server build with:

$ npm run dev

Then open http://localhost:3000 in your browser to view your App served directly from Nuxt.js dev server and will proxy all Server requests to ServiceStack Server running on https://localhost:5001. The url dotnet binds to is configurable in .env.

Update DTOs

Whilst Next.js is a JavaScript (ES 6/7) App it still benefits from ServiceStack's TypeScript Add Reference where you can generate typed DTOs with the dtos npm script:

$ npm run dtos

This will update the Servers interfaces/dtos.ts

Generate Static Production Build

Most of the time during development you'll be viewing your App through Next.js dev server to take advantage of it's Hot Module Replacement for instant UI updates. At any time you can also view a production build of your App with:

$ npm run build

Which will generate an encapsulated production build of your App in /wwwroot which you can view running from your ServiceStack Server App directly (npm run dotnet):

Publishing App for Deployment

To create a release client and server build of your App run:

$ npm run publish

Which will publish your App to bin/Release/net5/publish which you can deploy as a standard .NET Core App.

ss-next's People

Contributors

geooot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.